mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 16:56:40 +00:00
Compare commits
189 Commits
Author | SHA1 | Date | |
---|---|---|---|
942794b56c | |||
7dc3ab1d6b | |||
9f19bd14ca | |||
d0b1d09f38 | |||
53cd4b1306 | |||
d785ef31c8 | |||
97117c0e97 | |||
885f6196e8 | |||
9b0f928386 | |||
0bbe2d06f6 | |||
ff16347981 | |||
b39ba8ed86 | |||
f97649083a | |||
4d77d514fd | |||
92c07f89fe | |||
a775d258e9 | |||
7efa151157 | |||
7fe28ae8cb | |||
ce9b70bc98 | |||
079ea1050e | |||
1190c612b3 | |||
f8e019dd69 | |||
8ab337d0a6 | |||
ebfba89994 | |||
b78f71c238 | |||
bb8c34e0cd | |||
770fe65f98 | |||
9284ec3409 | |||
7d709319c6 | |||
0f76222f90 | |||
9557737915 | |||
5e1475dfb5 | |||
884a4ed1ec | |||
ae098410c1 | |||
abaf3ff980 | |||
b65c1ccd6d | |||
4450427d4e | |||
6c4903c3fe | |||
fd50589331 | |||
74faaf2d74 | |||
38b18e5867 | |||
048518dc49 | |||
8fc2f74275 | |||
c9da0177ad | |||
b23b7c0c1b | |||
842f96678d | |||
24e031acae | |||
f52c8462ae | |||
4e9984f251 | |||
457b6f4124 | |||
9d5794dcfd | |||
0e3eeaeac3 | |||
45b338fd9b | |||
3604add18a | |||
d716f77ac0 | |||
cbbdb0248f | |||
84edae26f5 | |||
8592978be2 | |||
7d0f3618c9 | |||
a24aa6a962 | |||
de13860741 | |||
b072e49d85 | |||
c80b6c9ff9 | |||
303f81d5cd | |||
6756f2db76 | |||
0af3603354 | |||
63fcd3a2b1 | |||
e484130d84 | |||
d55de3b4a8 | |||
2bc943b4c8 | |||
bc3893e2db | |||
6352975825 | |||
c665524078 | |||
dd661a7304 | |||
d699f6de02 | |||
07bc28fc48 | |||
bfdce97271 | |||
5fd22ba582 | |||
ead38212d5 | |||
36877ae2f2 | |||
fbd3983c0b | |||
44b07ec34f | |||
a9a8f80ee2 | |||
c27ddc19a6 | |||
2526e1750a | |||
f9a577035b | |||
edeecb51f4 | |||
8126caf184 | |||
faab60a07e | |||
922c3def81 | |||
ea834da575 | |||
6e4e634f59 | |||
2cde4a430c | |||
c3a426d6db | |||
e662491198 | |||
ec7e370a01 | |||
ef957467ce | |||
1a94c3e39f | |||
b1fcf5e348 | |||
7c27c03d98 | |||
cbf4004169 | |||
57eab45b43 | |||
4eeaf051ad | |||
285514b04a | |||
a00c6926c4 | |||
bae1e49c5e | |||
730f7c5ea0 | |||
67a382695a | |||
9600f2d5d9 | |||
81200f73d1 | |||
ee18ae324d | |||
7d2a25668a | |||
98c487c639 | |||
953f1813d3 | |||
df02ad6771 | |||
299aeae38e | |||
f622e6c295 | |||
5f93b7e1e5 | |||
b41015bfd8 | |||
14cd376f7e | |||
ce3758730f | |||
eb788f02dd | |||
096bb1bb24 | |||
223eaf30b3 | |||
6763878d74 | |||
81c656c86e | |||
6c09905a8d | |||
f0c646688e | |||
336f17b1cf | |||
583f502cee | |||
c071195aaf | |||
f62b084bbc | |||
c92a4bbdb9 | |||
9b0b7537c2 | |||
f8d25491d5 | |||
1dc0e05715 | |||
ffe8993ee1 | |||
90ef0a2121 | |||
7457e9e454 | |||
dc65187381 | |||
b449d732b0 | |||
8dfaaf7a8c | |||
6b7bfacbfd | |||
16186bdfbb | |||
4bbb73d1ff | |||
aa9f306586 | |||
08a004d65f | |||
d798904394 | |||
f78edc55d4 | |||
8866f44aa2 | |||
0fc2aa68b0 | |||
391677596a | |||
5988eba06b | |||
81d3cc8dde | |||
7b13ca0248 | |||
06fcf531af | |||
9f7ac310d9 | |||
09bc47f3fb | |||
8544775be2 | |||
c8c8fc9c59 | |||
14095fdebb | |||
dcecebdc8d | |||
f73c63f1e7 | |||
067094130f | |||
d16aa6de4c | |||
6086f761eb | |||
b2f1f7e055 | |||
3c20213c0d | |||
3500cae2da | |||
c4be024619 | |||
9849003ecc | |||
f274e20f84 | |||
f180eec44a | |||
b1ef89dae9 | |||
de20747d45 | |||
c801feed6f | |||
5fdc5826b7 | |||
a87a9241af | |||
8fb64b8499 | |||
10dd546c09 | |||
5a352b2ca0 | |||
333f38fb64 | |||
d55eaf0d3d | |||
e35d70bc3c | |||
e421867f63 | |||
ec7d814467 | |||
9c5a557316 | |||
38e79fd917 | |||
10e63f5e86 |
77
.github/workflows/codeql-analysis.yml
vendored
Normal file
77
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, server ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '29 4 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'java' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
|
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: 17
|
||||||
|
cache: gradle
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
chmod +x gradlew
|
||||||
|
./gradlew build --no-daemon
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,8 +1,7 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
/.idea/codeStyles/codeStyleConfig.xml
|
|
||||||
*.iml
|
*.iml
|
||||||
/target/
|
/target/
|
||||||
/src/main/resources/build.properties
|
server/src/main/resources/build.properties
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
@ -14,4 +13,5 @@ Thumbs.db
|
|||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
/build/
|
/build/
|
||||||
/.gradle/
|
/*/build/
|
||||||
|
/.gradle/
|
49
.idea/codeStyles/Plexus_Code_Style.xml
generated
Normal file
49
.idea/codeStyles/Plexus_Code_Style.xml
generated
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Plexus Code Style" version="1">
|
||||||
|
<JavaCodeStyleSettings>
|
||||||
|
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
|
||||||
|
<option name="IMPORT_LAYOUT_TABLE">
|
||||||
|
<value>
|
||||||
|
<package name="" withSubpackages="true" static="false" />
|
||||||
|
<package name="" withSubpackages="true" static="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</JavaCodeStyleSettings>
|
||||||
|
<JetCodeStyleSettings>
|
||||||
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
|
<value>
|
||||||
|
<package name="java.util" alias="false" withSubpackages="false" />
|
||||||
|
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||||
|
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||||
|
<value>
|
||||||
|
<package name="" alias="false" withSubpackages="true" />
|
||||||
|
<package name="java" alias="false" withSubpackages="true" />
|
||||||
|
<package name="javax" alias="false" withSubpackages="true" />
|
||||||
|
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||||
|
<package name="" alias="true" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</JetCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="JAVA">
|
||||||
|
<option name="BRACE_STYLE" value="2" />
|
||||||
|
<option name="CLASS_BRACE_STYLE" value="2" />
|
||||||
|
<option name="METHOD_BRACE_STYLE" value="2" />
|
||||||
|
<option name="LAMBDA_BRACE_STYLE" value="2" />
|
||||||
|
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="WHILE_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="CATCH_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="FINALLY_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
|
||||||
|
<option name="IF_BRACE_FORCE" value="3" />
|
||||||
|
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
||||||
|
<option name="WHILE_BRACE_FORCE" value="3" />
|
||||||
|
<option name="FOR_BRACE_FORCE" value="3" />
|
||||||
|
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="0" />
|
||||||
|
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
|
||||||
|
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
47
.idea/codeStyles/codeStyleConfig.xml
generated
47
.idea/codeStyles/codeStyleConfig.xml
generated
@ -1,46 +1,5 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<state>
|
||||||
<JavaCodeStyleSettings>
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Plexus Code Style" />
|
||||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
|
</state>
|
||||||
<option name="IMPORT_LAYOUT_TABLE">
|
|
||||||
<value>
|
|
||||||
<package name="" withSubpackages="true" static="false" />
|
|
||||||
<package name="" withSubpackages="true" static="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
</JavaCodeStyleSettings>
|
|
||||||
<JetCodeStyleSettings>
|
|
||||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
|
||||||
<value>
|
|
||||||
<package name="java.util" alias="false" withSubpackages="false" />
|
|
||||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
|
||||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
|
||||||
<value>
|
|
||||||
<package name="" alias="false" withSubpackages="true" />
|
|
||||||
<package name="java" alias="false" withSubpackages="true" />
|
|
||||||
<package name="javax" alias="false" withSubpackages="true" />
|
|
||||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
|
||||||
<package name="" alias="true" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
</JetCodeStyleSettings>
|
|
||||||
<codeStyleSettings language="JAVA">
|
|
||||||
<option name="BRACE_STYLE" value="2" />
|
|
||||||
<option name="CLASS_BRACE_STYLE" value="2" />
|
|
||||||
<option name="METHOD_BRACE_STYLE" value="2" />
|
|
||||||
<option name="LAMBDA_BRACE_STYLE" value="2" />
|
|
||||||
<option name="ELSE_ON_NEW_LINE" value="true" />
|
|
||||||
<option name="WHILE_ON_NEW_LINE" value="true" />
|
|
||||||
<option name="CATCH_ON_NEW_LINE" value="true" />
|
|
||||||
<option name="FINALLY_ON_NEW_LINE" value="true" />
|
|
||||||
<option name="SPACE_AFTER_TYPE_CAST" value="false" />
|
|
||||||
<option name="IF_BRACE_FORCE" value="3" />
|
|
||||||
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
|
||||||
<option name="WHILE_BRACE_FORCE" value="3" />
|
|
||||||
<option name="FOR_BRACE_FORCE" value="3" />
|
|
||||||
</codeStyleSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
</component>
|
36
CONTRIBUTING.md
Normal file
36
CONTRIBUTING.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when
|
||||||
|
contributing however.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
|
||||||
|
1. Make an issue and get feedback. It's important to know if your idea will be accepted before writing any code.
|
||||||
|
|
||||||
|
- If it is a feature request, describe the feature and be extremely specific.
|
||||||
|
- If it is a bug report, ensure you include how to reproduce the bug and the expected outcome
|
||||||
|
- If it is an enhancement, describe your proposed changes. Ensure you are extremely specific.
|
||||||
|
|
||||||
|
2. Fork this project
|
||||||
|
3. Create a new branch that describes the new feature, enhancement, or bug fix. For example, this is
|
||||||
|
good: `feature/add-xyz`. This is bad: `fix-this-lol`.
|
||||||
|
4. Write the code that addresses your change.
|
||||||
|
|
||||||
|
- Keep in mind that it **must** be formatted correctly. If you are using IntelliJ, there is a `codeStyle.xml` file that
|
||||||
|
tells IntelliJ how to format your code. Check this link for information on how to use the
|
||||||
|
file: https://www.jetbrains.com/help/idea/configuring-code-style.html#import-export-schemes
|
||||||
|
- If you are not using IntelliJ, that is fine. We use Allman style so please format your code accordingly.
|
||||||
|
|
||||||
|
6. Push your changes to your new branch and make a PR based off of that branch.
|
||||||
|
|
||||||
|
## Requirements for a PR
|
||||||
|
|
||||||
|
- The issue must be marked as approved
|
||||||
|
- It must only address each specific issue. Don't make one PR for multiple issues.
|
||||||
|
- Your PR must compile and work. If it does not compile or work, your PR will most likely be rejected.
|
||||||
|
|
||||||
|
## Code requirements
|
||||||
|
|
||||||
|
- Most importantly, your code must be efficient. Your pull request may be rejected if your code is deemed inefficient or
|
||||||
|
sloppy.
|
||||||
|
- Do not repeat yourself. Create functions as needed if you're using large blocks of code over and over again.
|
||||||
|
- Do not use an excessive amount of commits when making your PR. It makes the master branch look messy.
|
||||||
|
- Your code must be consistent with Plex's codebase. If a function already exists, use it.
|
4
Jenkinsfile
vendored
4
Jenkinsfile
vendored
@ -24,8 +24,8 @@ pipeline {
|
|||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
archiveArtifacts artifacts: "build/libs/*.jar", fingerprint: true
|
archiveArtifacts artifacts: "build/libs/*.jar", fingerprint: true
|
||||||
javadoc javadocDir: "build/docs/javadoc", keepAll: false
|
javadoc javadocDir: "api/build/docs/javadoc", keepAll: false
|
||||||
discordSend description: "**Build:** ${env.BUILD_NUMBER}\n**Status:** ${currentBuild.currentResult}", enableArtifactsList: true, footer: "Built with Jenkins", link: env.BUILD_URL, result: currentBuild.currentResult, scmWebUrl: "https://github.com/plexusorg/Plex", showChangeset: true, title: env.JOB_NAME, webhookURL: env.PLEX_WEBHOOK_URL
|
discordSend description: "**Build:** ${env.BUILD_NUMBER}\n**Status:** ${currentBuild.currentResult}", enableArtifactsList: true, footer: "Built with Jenkins", link: env.BUILD_URL, result: currentBuild.currentResult, scmWebUrl: "https://github.com/plexusorg/Plex", showChangeset: true, title: env.JOB_NAME, webhookURL: env.WEBHOOK_URL
|
||||||
cleanWs()
|
cleanWs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
320
LICENSE.md
320
LICENSE.md
@ -1,190 +1,190 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
The GNU General Public License is a free, copyleft license for
|
||||||
software and other kinds of works.
|
software and other kinds of works.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
share and change all versions of a program--to make sure it remains free
|
share and change all versions of a program--to make sure it remains free
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
GNU General Public License for most of our software; it applies also to
|
GNU General Public License for most of our software; it applies also to
|
||||||
any other work released this way by its authors. You can apply it to
|
any other work released this way by its authors. You can apply it to
|
||||||
your programs, too.
|
your programs, too.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
have the freedom to distribute copies of free software (and charge for
|
have the freedom to distribute copies of free software (and charge for
|
||||||
them if you wish), that you receive source code or can get it if you
|
them if you wish), that you receive source code or can get it if you
|
||||||
want it, that you can change the software or use pieces of it in new
|
want it, that you can change the software or use pieces of it in new
|
||||||
free programs, and that you know you can do these things.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
To protect your rights, we need to prevent others from denying you
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
For example, if you distribute copies of such a program, whether
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
or can get the source code. And you must show them these terms so they
|
or can get the source code. And you must show them these terms so they
|
||||||
know their rights.
|
know their rights.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
that there is no warranty for this free software. For both users' and
|
that there is no warranty for this free software. For both users' and
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
changed, so that their problems will not be attributed erroneously to
|
changed, so that their problems will not be attributed erroneously to
|
||||||
authors of previous versions.
|
authors of previous versions.
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
Some devices are designed to deny users access to install or run
|
||||||
modified versions of the software inside them, although the manufacturer
|
modified versions of the software inside them, although the manufacturer
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
protecting users' freedom to change the software. The systematic
|
protecting users' freedom to change the software. The systematic
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
products. If such problems arise substantially in other domains, we
|
products. If such problems arise substantially in other domains, we
|
||||||
stand ready to extend this provision to those domains in future versions
|
stand ready to extend this provision to those domains in future versions
|
||||||
of the GPL, as needed to protect the freedom of users.
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
Finally, every program is threatened constantly by software patents.
|
||||||
States should not allow patents to restrict development and use of
|
States should not allow patents to restrict development and use of
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
avoid the special danger that patents applied to a free program could
|
avoid the special danger that patents applied to a free program could
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
patents cannot be used to render the program non-free.
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
works, such as semiconductor masks.
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
"recipients" may be individuals or organizations.
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
earlier work or a work "based on" the earlier work.
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
A "covered work" means either the unmodified Program or a work based
|
||||||
on the Program.
|
on the Program.
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
To "propagate" a work means to do anything with it that, without
|
||||||
permission, would make you directly or secondarily liable for
|
permission, would make you directly or secondarily liable for
|
||||||
infringement under applicable copyright law, except executing it on a
|
infringement under applicable copyright law, except executing it on a
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
distribution (with or without modification), making available to the
|
distribution (with or without modification), making available to the
|
||||||
public, and in some countries other activities as well.
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
To "convey" a work means any kind of propagation that enables other
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
to the extent that it includes a convenient and prominently visible
|
to the extent that it includes a convenient and prominently visible
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
tells the user that there is no warranty for the work (except to the
|
tells the user that there is no warranty for the work (except to the
|
||||||
extent that warranties are provided), that licensees may convey the
|
extent that warranties are provided), that licensees may convey the
|
||||||
work under this License, and how to view a copy of this License. If
|
work under this License, and how to view a copy of this License. If
|
||||||
the interface presents a list of user commands or options, such as a
|
the interface presents a list of user commands or options, such as a
|
||||||
menu, a prominent item in the list meets this criterion.
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
1. Source Code.
|
1. Source Code.
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
The "source code" for a work means the preferred form of the work
|
||||||
for making modifications to it. "Object code" means any non-source
|
for making modifications to it. "Object code" means any non-source
|
||||||
form of a work.
|
form of a work.
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
A "Standard Interface" means an interface that either is an official
|
||||||
standard defined by a recognized standards body, or, in the case of
|
standard defined by a recognized standards body, or, in the case of
|
||||||
interfaces specified for a particular programming language, one that
|
interfaces specified for a particular programming language, one that
|
||||||
is widely used among developers working in that language.
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
The "System Libraries" of an executable work include anything, other
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
packaging a Major Component, but which is not part of that Major
|
packaging a Major Component, but which is not part of that Major
|
||||||
Component, and (b) serves only to enable use of the work with that
|
Component, and (b) serves only to enable use of the work with that
|
||||||
Major Component, or to implement a Standard Interface for which an
|
Major Component, or to implement a Standard Interface for which an
|
||||||
implementation is available to the public in source code form. A
|
implementation is available to the public in source code form. A
|
||||||
"Major Component", in this context, means a major essential component
|
"Major Component", in this context, means a major essential component
|
||||||
(kernel, window system, and so on) of the specific operating system
|
(kernel, window system, and so on) of the specific operating system
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
produce the work, or an object code interpreter used to run it.
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
The "Corresponding Source" for a work in object code form means all
|
||||||
the source code needed to generate, install, and (for an executable
|
the source code needed to generate, install, and (for an executable
|
||||||
work) run the object code and to modify the work, including scripts to
|
work) run the object code and to modify the work, including scripts to
|
||||||
control those activities. However, it does not include the work's
|
control those activities. However, it does not include the work's
|
||||||
System Libraries, or general-purpose tools or generally available free
|
System Libraries, or general-purpose tools or generally available free
|
||||||
programs which are used unmodified in performing those activities but
|
programs which are used unmodified in performing those activities but
|
||||||
which are not part of the work. For example, Corresponding Source
|
which are not part of the work. For example, Corresponding Source
|
||||||
includes interface definition files associated with source files for
|
includes interface definition files associated with source files for
|
||||||
the work, and the source code for shared libraries and dynamically
|
the work, and the source code for shared libraries and dynamically
|
||||||
linked subprograms that the work is specifically designed to require,
|
linked subprograms that the work is specifically designed to require,
|
||||||
such as by intimate data communication or control flow between those
|
such as by intimate data communication or control flow between those
|
||||||
subprograms and other parts of the work.
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
The Corresponding Source need not include anything that users
|
||||||
can regenerate automatically from other parts of the Corresponding
|
can regenerate automatically from other parts of the Corresponding
|
||||||
Source.
|
Source.
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
The Corresponding Source for a work in source code form is that
|
||||||
same work.
|
same work.
|
||||||
|
|
||||||
2. Basic Permissions.
|
2. Basic Permissions.
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
All rights granted under this License are granted for the term of
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
permission to run the unmodified Program. The output from running a
|
permission to run the unmodified Program. The output from running a
|
||||||
covered work is covered by this License only if the output, given its
|
covered work is covered by this License only if the output, given its
|
||||||
content, constitutes a covered work. This License acknowledges your
|
content, constitutes a covered work. This License acknowledges your
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
You may make, run and propagate covered works that you do not
|
||||||
convey, without conditions so long as your license otherwise remains
|
convey, without conditions so long as your license otherwise remains
|
||||||
in force. You may convey covered works to others for the sole purpose
|
in force. You may convey covered works to others for the sole purpose
|
||||||
of having them make modifications exclusively for you, or provide you
|
of having them make modifications exclusively for you, or provide you
|
||||||
with facilities for running those works, provided that you comply with
|
with facilities for running those works, provided that you comply with
|
||||||
the terms of this License in conveying all material for which you do
|
the terms of this License in conveying all material for which you do
|
||||||
not control copyright. Those thus making or running the covered works
|
not control copyright. Those thus making or running the covered works
|
||||||
for you must do so exclusively on your behalf, under your direction
|
for you must do so exclusively on your behalf, under your direction
|
||||||
and control, on terms that prohibit them from making any copies of
|
and control, on terms that prohibit them from making any copies of
|
||||||
your copyrighted material outside their relationship with you.
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
Conveying under any other circumstances is permitted solely under
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
makes it unnecessary.
|
makes it unnecessary.
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
No covered work shall be deemed part of an effective technological
|
||||||
measure under any applicable law fulfilling obligations under article
|
measure under any applicable law fulfilling obligations under article
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
similar laws prohibiting or restricting circumvention of such
|
similar laws prohibiting or restricting circumvention of such
|
||||||
measures.
|
measures.
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
circumvention of technological measures to the extent such circumvention
|
circumvention of technological measures to the extent such circumvention
|
||||||
is effected by exercising rights under this License with respect to
|
is effected by exercising rights under this License with respect to
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
@ -192,9 +192,9 @@ modification of the work as a means of enforcing, against the work's
|
|||||||
users, your or third parties' legal rights to forbid circumvention of
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
technological measures.
|
technological measures.
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
You may convey verbatim copies of the Program's source code as you
|
||||||
receive it, in any medium, provided that you conspicuously and
|
receive it, in any medium, provided that you conspicuously and
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
keep intact all notices stating that this License and any
|
keep intact all notices stating that this License and any
|
||||||
@ -202,12 +202,12 @@ non-permissive terms added in accord with section 7 apply to the code;
|
|||||||
keep intact all notices of the absence of any warranty; and give all
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
recipients a copy of this License along with the Program.
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
You may charge any price or no price for each copy that you convey,
|
||||||
and you may offer support or warranty protection for a fee.
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
You may convey a work based on the Program, or the modifications to
|
||||||
produce it from the Program, in the form of source code under the
|
produce it from the Program, in the form of source code under the
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
@ -232,19 +232,19 @@ terms of section 4, provided that you also meet all of these conditions:
|
|||||||
interfaces that do not display Appropriate Legal Notices, your
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
work need not make them do so.
|
work need not make them do so.
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
A compilation of a covered work with other separate and independent
|
||||||
works, which are not by their nature extensions of the covered work,
|
works, which are not by their nature extensions of the covered work,
|
||||||
and which are not combined with it such as to form a larger program,
|
and which are not combined with it such as to form a larger program,
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
used to limit the access or legal rights of the compilation's users
|
used to limit the access or legal rights of the compilation's users
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
in an aggregate does not cause this License to apply to the other
|
in an aggregate does not cause this License to apply to the other
|
||||||
parts of the aggregate.
|
parts of the aggregate.
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
You may convey a covered work in object code form under the terms
|
||||||
of sections 4 and 5, provided that you also convey the
|
of sections 4 and 5, provided that you also convey the
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
in one of these ways:
|
in one of these ways:
|
||||||
@ -290,75 +290,75 @@ in one of these ways:
|
|||||||
Source of the work are being offered to the general public at no
|
Source of the work are being offered to the general public at no
|
||||||
charge under subsection 6d.
|
charge under subsection 6d.
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
A separable portion of the object code, whose source code is excluded
|
||||||
from the Corresponding Source as a System Library, need not be
|
from the Corresponding Source as a System Library, need not be
|
||||||
included in conveying the object code work.
|
included in conveying the object code work.
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
tangible personal property which is normally used for personal, family,
|
tangible personal property which is normally used for personal, family,
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
product received by a particular user, "normally used" refers to a
|
product received by a particular user, "normally used" refers to a
|
||||||
typical or common use of that class of product, regardless of the status
|
typical or common use of that class of product, regardless of the status
|
||||||
of the particular user or of the way in which the particular user
|
of the particular user or of the way in which the particular user
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
is a consumer product regardless of whether the product has substantial
|
is a consumer product regardless of whether the product has substantial
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
the only significant mode of use of the product.
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
"Installation Information" for a User Product means any methods,
|
||||||
procedures, authorization keys, or other information required to install
|
procedures, authorization keys, or other information required to install
|
||||||
and execute modified versions of a covered work in that User Product from
|
and execute modified versions of a covered work in that User Product from
|
||||||
a modified version of its Corresponding Source. The information must
|
a modified version of its Corresponding Source. The information must
|
||||||
suffice to ensure that the continued functioning of the modified object
|
suffice to ensure that the continued functioning of the modified object
|
||||||
code is in no case prevented or interfered with solely because
|
code is in no case prevented or interfered with solely because
|
||||||
modification has been made.
|
modification has been made.
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
If you convey an object code work under this section in, or with, or
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
part of a transaction in which the right of possession and use of the
|
part of a transaction in which the right of possession and use of the
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
by the Installation Information. But this requirement does not apply
|
by the Installation Information. But this requirement does not apply
|
||||||
if neither you nor any third party retains the ability to install
|
if neither you nor any third party retains the ability to install
|
||||||
modified object code on the User Product (for example, the work has
|
modified object code on the User Product (for example, the work has
|
||||||
been installed in ROM).
|
been installed in ROM).
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
The requirement to provide Installation Information does not include a
|
||||||
requirement to continue to provide support service, warranty, or updates
|
requirement to continue to provide support service, warranty, or updates
|
||||||
for a work that has been modified or installed by the recipient, or for
|
for a work that has been modified or installed by the recipient, or for
|
||||||
the User Product in which it has been modified or installed. Access to a
|
the User Product in which it has been modified or installed. Access to a
|
||||||
network may be denied when the modification itself materially and
|
network may be denied when the modification itself materially and
|
||||||
adversely affects the operation of the network or violates the rules and
|
adversely affects the operation of the network or violates the rules and
|
||||||
protocols for communication across the network.
|
protocols for communication across the network.
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
in accord with this section must be in a format that is publicly
|
in accord with this section must be in a format that is publicly
|
||||||
documented (and with an implementation available to the public in
|
documented (and with an implementation available to the public in
|
||||||
source code form), and must require no special password or key for
|
source code form), and must require no special password or key for
|
||||||
unpacking, reading or copying.
|
unpacking, reading or copying.
|
||||||
|
|
||||||
7. Additional Terms.
|
7. Additional Terms.
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
License by making exceptions from one or more of its conditions.
|
License by making exceptions from one or more of its conditions.
|
||||||
Additional permissions that are applicable to the entire Program shall
|
Additional permissions that are applicable to the entire Program shall
|
||||||
be treated as though they were included in this License, to the extent
|
be treated as though they were included in this License, to the extent
|
||||||
that they are valid under applicable law. If additional permissions
|
that they are valid under applicable law. If additional permissions
|
||||||
apply only to part of the Program, that part may be used separately
|
apply only to part of the Program, that part may be used separately
|
||||||
under those permissions, but the entire Program remains governed by
|
under those permissions, but the entire Program remains governed by
|
||||||
this License without regard to the additional permissions.
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
When you convey a copy of a covered work, you may at your option
|
||||||
remove any additional permissions from that copy, or from any part of
|
remove any additional permissions from that copy, or from any part of
|
||||||
it. (Additional permissions may be written to require their own
|
it. (Additional permissions may be written to require their own
|
||||||
removal in certain cases when you modify the work.) You may place
|
removal in certain cases when you modify the work.) You may place
|
||||||
additional permissions on material, added by you to a covered work,
|
additional permissions on material, added by you to a covered work,
|
||||||
for which you have or can give appropriate copyright permission.
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
Notwithstanding any other provision of this License, for material you
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
that material) supplement the terms of this License with terms:
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
@ -385,74 +385,74 @@ that material) supplement the terms of this License with terms:
|
|||||||
any liability that these contractual assumptions directly impose on
|
any liability that these contractual assumptions directly impose on
|
||||||
those licensors and authors.
|
those licensors and authors.
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
All other non-permissive additional terms are considered "further
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
received it, or any part of it, contains a notice stating that it is
|
received it, or any part of it, contains a notice stating that it is
|
||||||
governed by this License along with a term that is a further
|
governed by this License along with a term that is a further
|
||||||
restriction, you may remove that term. If a license document contains
|
restriction, you may remove that term. If a license document contains
|
||||||
a further restriction but permits relicensing or conveying under this
|
a further restriction but permits relicensing or conveying under this
|
||||||
License, you may add to a covered work material governed by the terms
|
License, you may add to a covered work material governed by the terms
|
||||||
of that license document, provided that the further restriction does
|
of that license document, provided that the further restriction does
|
||||||
not survive such relicensing or conveying.
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
If you add terms to a covered work in accord with this section, you
|
||||||
must place, in the relevant source files, a statement of the
|
must place, in the relevant source files, a statement of the
|
||||||
additional terms that apply to those files, or a notice indicating
|
additional terms that apply to those files, or a notice indicating
|
||||||
where to find the applicable terms.
|
where to find the applicable terms.
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
form of a separately written license, or stated as exceptions;
|
form of a separately written license, or stated as exceptions;
|
||||||
the above requirements apply either way.
|
the above requirements apply either way.
|
||||||
|
|
||||||
8. Termination.
|
8. Termination.
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
You may not propagate or modify a covered work except as expressly
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
modify it is void, and will automatically terminate your rights under
|
modify it is void, and will automatically terminate your rights under
|
||||||
this License (including any patent licenses granted under the third
|
this License (including any patent licenses granted under the third
|
||||||
paragraph of section 11).
|
paragraph of section 11).
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
However, if you cease all violation of this License, then your
|
||||||
license from a particular copyright holder is reinstated (a)
|
license from a particular copyright holder is reinstated (a)
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
holder fails to notify you of the violation by some reasonable means
|
holder fails to notify you of the violation by some reasonable means
|
||||||
prior to 60 days after the cessation.
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
Moreover, your license from a particular copyright holder is
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
violation by some reasonable means, this is the first time you have
|
violation by some reasonable means, this is the first time you have
|
||||||
received notice of violation of this License (for any work) from that
|
received notice of violation of this License (for any work) from that
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
your receipt of the notice.
|
your receipt of the notice.
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
Termination of your rights under this section does not terminate the
|
||||||
licenses of parties who have received copies or rights from you under
|
licenses of parties who have received copies or rights from you under
|
||||||
this License. If your rights have been terminated and not permanently
|
this License. If your rights have been terminated and not permanently
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
material under section 10.
|
material under section 10.
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
You are not required to accept this License in order to receive or
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
to receive a copy likewise does not require acceptance. However,
|
to receive a copy likewise does not require acceptance. However,
|
||||||
nothing other than this License grants you permission to propagate or
|
nothing other than this License grants you permission to propagate or
|
||||||
modify any covered work. These actions infringe copyright if you do
|
modify any covered work. These actions infringe copyright if you do
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
Each time you convey a covered work, the recipient automatically
|
||||||
receives a license from the original licensors, to run, modify and
|
receives a license from the original licensors, to run, modify and
|
||||||
propagate that work, subject to this License. You are not responsible
|
propagate that work, subject to this License. You are not responsible
|
||||||
for enforcing compliance by third parties with this License.
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
An "entity transaction" is a transaction transferring control of an
|
||||||
organization, or substantially all assets of one, or subdividing an
|
organization, or substantially all assets of one, or subdividing an
|
||||||
organization, or merging organizations. If propagation of a covered
|
organization, or merging organizations. If propagation of a covered
|
||||||
work results from an entity transaction, each party to that
|
work results from an entity transaction, each party to that
|
||||||
transaction who receives a copy of the work also receives whatever
|
transaction who receives a copy of the work also receives whatever
|
||||||
licenses to the work the party's predecessor in interest had or could
|
licenses to the work the party's predecessor in interest had or could
|
||||||
@ -460,43 +460,43 @@ give under the previous paragraph, plus a right to possession of the
|
|||||||
Corresponding Source of the work from the predecessor in interest, if
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
You may not impose any further restrictions on the exercise of the
|
||||||
rights granted or affirmed under this License. For example, you may
|
rights granted or affirmed under this License. For example, you may
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
rights granted under this License, and you may not initiate litigation
|
rights granted under this License, and you may not initiate litigation
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
sale, or importing the Program or any portion of it.
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
11. Patents.
|
11. Patents.
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
License of the Program or a work on which the Program is based. The
|
License of the Program or a work on which the Program is based. The
|
||||||
work thus licensed is called the contributor's "contributor version".
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
A contributor's "essential patent claims" are all patent claims
|
||||||
owned or controlled by the contributor, whether already acquired or
|
owned or controlled by the contributor, whether already acquired or
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
by this License, of making, using, or selling its contributor version,
|
by this License, of making, using, or selling its contributor version,
|
||||||
but do not include claims that would be infringed only as a
|
but do not include claims that would be infringed only as a
|
||||||
consequence of further modification of the contributor version. For
|
consequence of further modification of the contributor version. For
|
||||||
purposes of this definition, "control" includes the right to grant
|
purposes of this definition, "control" includes the right to grant
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
this License.
|
this License.
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
patent license under the contributor's essential patent claims, to
|
patent license under the contributor's essential patent claims, to
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
propagate the contents of its contributor version.
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
In the following three paragraphs, a "patent license" is any express
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
(such as an express permission to practice a patent or covenant not to
|
(such as an express permission to practice a patent or covenant not to
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
party means to make such an agreement or commitment not to enforce a
|
party means to make such an agreement or commitment not to enforce a
|
||||||
patent against the party.
|
patent against the party.
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
and the Corresponding Source of the work is not available for anyone
|
and the Corresponding Source of the work is not available for anyone
|
||||||
to copy, free of charge and under the terms of this License, through a
|
to copy, free of charge and under the terms of this License, through a
|
||||||
publicly available network server or other readily accessible means,
|
publicly available network server or other readily accessible means,
|
||||||
@ -510,7 +510,7 @@ covered work in a country, or your recipient's use of the covered work
|
|||||||
in a country, would infringe one or more identifiable patents in that
|
in a country, would infringe one or more identifiable patents in that
|
||||||
country that you have reason to believe are valid.
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
If, pursuant to or in connection with a single transaction or
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
covered work, and grant a patent license to some of the parties
|
covered work, and grant a patent license to some of the parties
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
@ -518,10 +518,10 @@ or convey a specific copy of the covered work, then the patent license
|
|||||||
you grant is automatically extended to all recipients of the covered
|
you grant is automatically extended to all recipients of the covered
|
||||||
work and works based on it.
|
work and works based on it.
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
A patent license is "discriminatory" if it does not include within
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
specifically granted under this License. You may not convey a covered
|
specifically granted under this License. You may not convey a covered
|
||||||
work if you are a party to an arrangement with a third party that is
|
work if you are a party to an arrangement with a third party that is
|
||||||
in the business of distributing software, under which you make payment
|
in the business of distributing software, under which you make payment
|
||||||
to the third party based on the extent of your activity of conveying
|
to the third party based on the extent of your activity of conveying
|
||||||
@ -533,73 +533,73 @@ for and in connection with specific products or compilations that
|
|||||||
contain the covered work, unless you entered into that arrangement,
|
contain the covered work, unless you entered into that arrangement,
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
any implied license or other defenses to infringement that may
|
any implied license or other defenses to infringement that may
|
||||||
otherwise be available to you under applicable patent law.
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
the Program, the only way you could satisfy both those terms and this
|
the Program, the only way you could satisfy both those terms and this
|
||||||
License would be to refrain entirely from conveying the Program.
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
Notwithstanding any other provision of this License, you have
|
||||||
permission to link or combine any covered work with a work licensed
|
permission to link or combine any covered work with a work licensed
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
combined work, and to convey the resulting work. The terms of this
|
combined work, and to convey the resulting work. The terms of this
|
||||||
License will continue to apply to the part which is the covered work,
|
License will continue to apply to the part which is the covered work,
|
||||||
but the special requirements of the GNU Affero General Public License,
|
but the special requirements of the GNU Affero General Public License,
|
||||||
section 13, concerning interaction through a network will apply to the
|
section 13, concerning interaction through a network will apply to the
|
||||||
combination as such.
|
combination as such.
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
the GNU General Public License from time to time. Such new versions will
|
the GNU General Public License from time to time. Such new versions will
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the
|
||||||
Program specifies that a certain numbered version of the GNU General
|
Program specifies that a certain numbered version of the GNU General
|
||||||
Public License "or any later version" applies to it, you have the
|
Public License "or any later version" applies to it, you have the
|
||||||
option of following the terms and conditions either of that numbered
|
option of following the terms and conditions either of that numbered
|
||||||
version or of any later version published by the Free Software
|
version or of any later version published by the Free Software
|
||||||
Foundation. If the Program does not specify a version number of the
|
Foundation. If the Program does not specify a version number of the
|
||||||
GNU General Public License, you may choose any version ever published
|
GNU General Public License, you may choose any version ever published
|
||||||
by the Free Software Foundation.
|
by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
public statement of acceptance of a version permanently authorizes you
|
public statement of acceptance of a version permanently authorizes you
|
||||||
to choose that version for the Program.
|
to choose that version for the Program.
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
Later license versions may give you additional or different
|
||||||
permissions. However, no additional obligations are imposed on any
|
permissions. However, no additional obligations are imposed on any
|
||||||
author or copyright holder as a result of your choosing to follow a
|
author or copyright holder as a result of your choosing to follow a
|
||||||
later version.
|
later version.
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
16. Limitation of Liability.
|
16. Limitation of Liability.
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
@ -609,9 +609,9 @@ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGES.
|
SUCH DAMAGES.
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
above cannot be given local legal effect according to their terms,
|
above cannot be given local legal effect according to their terms,
|
||||||
reviewing courts shall apply local law that most closely approximates
|
reviewing courts shall apply local law that most closely approximates
|
||||||
an absolute waiver of all civil liability in connection with the
|
an absolute waiver of all civil liability in connection with the
|
||||||
@ -622,11 +622,11 @@ copy of the Program in return for a fee.
|
|||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
If you develop a new program, and you want it to be of the greatest
|
||||||
possible use to the public, the best way to achieve this is to make it
|
possible use to the public, the best way to achieve this is to make it
|
||||||
free software which everyone can redistribute and change under these terms.
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
To do so, attach the following notices to the program. It is safest
|
||||||
to attach them to the start of each source file to most effectively
|
to attach them to the start of each source file to most effectively
|
||||||
state the exclusion of warranty; and each file should have at least
|
state the exclusion of warranty; and each file should have at least
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
@ -649,7 +649,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
<program> Copyright (C) <year> <name of author>
|
||||||
@ -658,17 +658,17 @@ notice like this when it starts in an interactive mode:
|
|||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
parts of the General Public License. Of course, your program's commands
|
parts of the General Public License. Of course, your program's commands
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
<https://www.gnu.org/licenses/>.
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
The GNU General Public License does not permit incorporating your program
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
may consider it more useful to permit linking proprietary applications with
|
may consider it more useful to permit linking proprietary applications with
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
Public License instead of this License. But first, please read
|
Public License instead of this License. But first, please read
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
# Plex
|
# Plex [](https://ci.plex.us.org/job/Plex/job/master/)
|
||||||
|
|
||||||
A new freedom plugin.
|
Plex is a new freedom plugin. It is an alternative to TotalFreedomMod. It has many of the features that make a freedom
|
||||||
|
server unique, but also many features that TotalFreedomMod doesn’t have. For example, there is full support for using a
|
||||||
|
permissions plugin instead of ranks. It is also much more performance oriented. You can use Redis to store indefinite
|
||||||
|
bans and store player data in MongoDB, MariaDB, or SQLite. Plex is also fully customizable as you can change almost all
|
||||||
|
of the messages within the plugin. Plex also has a module system which can be used to add additional functionality. Plex
|
||||||
|
is not a rewrite, "debloat", or related to TotalFreedomMod. Plex is an entirely new experience.
|
32
api/build.gradle
Normal file
32
api/build.gradle
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
group = rootProject.group
|
||||||
|
version = rootProject.version
|
||||||
|
description = "Plex-API"
|
||||||
|
|
||||||
|
jar {
|
||||||
|
archiveBaseName.set("Plex-API")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
jar {
|
||||||
|
finalizedBy(rootProject.tasks.copyJars)
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
maven(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly "org.projectlombok:lombok:1.18.24"
|
||||||
|
annotationProcessor "org.projectlombok:lombok:1.18.24"
|
||||||
|
compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT"
|
||||||
|
compileOnly "org.json:json:20220320"
|
||||||
|
}
|
11
api/src/main/java/dev/plex/api/IPlayerCache.java
Normal file
11
api/src/main/java/dev/plex/api/IPlayerCache.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package dev.plex.api;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface IPlayerCache<T>
|
||||||
|
{
|
||||||
|
Map<UUID, T> getPlexPlayerMap();
|
||||||
|
|
||||||
|
T getPlexPlayer(UUID uuid);
|
||||||
|
}
|
6
api/src/main/java/dev/plex/api/PlexApi.java
Normal file
6
api/src/main/java/dev/plex/api/PlexApi.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package dev.plex.api;
|
||||||
|
|
||||||
|
public interface PlexApi
|
||||||
|
{
|
||||||
|
IPlayerCache<?> getPlayerCache();
|
||||||
|
}
|
6
api/src/main/java/dev/plex/api/PlexApiProvider.java
Normal file
6
api/src/main/java/dev/plex/api/PlexApiProvider.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package dev.plex.api;
|
||||||
|
|
||||||
|
public interface PlexApiProvider
|
||||||
|
{
|
||||||
|
PlexApi getApi();
|
||||||
|
}
|
8
api/src/main/java/dev/plex/api/chat/IChatHandler.java
Normal file
8
api/src/main/java/dev/plex/api/chat/IChatHandler.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package dev.plex.api.chat;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
|
||||||
|
public interface IChatHandler
|
||||||
|
{
|
||||||
|
void doChat(AsyncChatEvent event);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -8,7 +8,7 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that is ran when a player is added to the admin list
|
* Event that is run when a player is added to the admin list
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Data
|
@Data
|
||||||
@ -24,7 +24,7 @@ public class AdminAddEvent extends Event
|
|||||||
/**
|
/**
|
||||||
* The PlexPlayer that was added
|
* The PlexPlayer that was added
|
||||||
*/
|
*/
|
||||||
private final PlexPlayer plexPlayer;
|
private final IPlexPlayer plexPlayer;
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
public static HandlerList getHandlerList()
|
||||||
{
|
{
|
||||||
@ -36,5 +36,4 @@ public class AdminAddEvent extends Event
|
|||||||
{
|
{
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -8,7 +8,7 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that is ran when a player is removed from the admin list
|
* Event that is run when a player is removed from the admin list
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Data
|
@Data
|
||||||
@ -24,7 +24,7 @@ public class AdminRemoveEvent extends Event
|
|||||||
/**
|
/**
|
||||||
* The PlexPlayer that was removed
|
* The PlexPlayer that was removed
|
||||||
*/
|
*/
|
||||||
private final PlexPlayer plexPlayer;
|
private final IPlexPlayer plexPlayer;
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
public static HandlerList getHandlerList()
|
||||||
{
|
{
|
@ -1,7 +1,7 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.api.rank.IRank;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -9,7 +9,7 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that is ran when an admin's rank is set
|
* Event that is run when an admins rank is set
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Data
|
@Data
|
||||||
@ -25,12 +25,12 @@ public class AdminSetRankEvent extends Event
|
|||||||
/**
|
/**
|
||||||
* The PlexPlayer that was removed
|
* The PlexPlayer that was removed
|
||||||
*/
|
*/
|
||||||
private final PlexPlayer plexPlayer;
|
private final IPlexPlayer plexPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rank the player was set to
|
* The rank the player was set to
|
||||||
*/
|
*/
|
||||||
private final Rank rank;
|
private final IRank rank;
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
public static HandlerList getHandlerList()
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
@ -1,7 +1,6 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -17,7 +16,7 @@ public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancell
|
|||||||
/**
|
/**
|
||||||
* The player who was punished
|
* The player who was punished
|
||||||
*/
|
*/
|
||||||
protected PlexPlayer punishedPlayer;
|
protected IPlexPlayer punishedPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the event was cancelled
|
* Whether the event was cancelled
|
||||||
@ -29,9 +28,9 @@ public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancell
|
|||||||
* Creates an event object
|
* Creates an event object
|
||||||
*
|
*
|
||||||
* @param punishedPlayer The player who was punished
|
* @param punishedPlayer The player who was punished
|
||||||
* @see PlexPlayer
|
* @see IPlexPlayer
|
||||||
*/
|
*/
|
||||||
protected PunishedPlayerEvent(PlexPlayer punishedPlayer)
|
protected PunishedPlayerEvent(IPlexPlayer punishedPlayer)
|
||||||
{
|
{
|
||||||
super(Bukkit.getPlayer(punishedPlayer.getUuid()));
|
super(Bukkit.getPlayer(punishedPlayer.getUuid()));
|
||||||
this.punishedPlayer = punishedPlayer;
|
this.punishedPlayer = punishedPlayer;
|
@ -1,6 +1,6 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -24,7 +24,7 @@ public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Ca
|
|||||||
* @param punishedPlayer The player who was punished
|
* @param punishedPlayer The player who was punished
|
||||||
* @param frozen The new frozen status
|
* @param frozen The new frozen status
|
||||||
*/
|
*/
|
||||||
public PunishedPlayerFreezeEvent(PlexPlayer punishedPlayer, boolean frozen)
|
public PunishedPlayerFreezeEvent(IPlexPlayer punishedPlayer, boolean frozen)
|
||||||
{
|
{
|
||||||
super(punishedPlayer);
|
super(punishedPlayer);
|
||||||
this.frozen = frozen;
|
this.frozen = frozen;
|
@ -1,6 +1,6 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -24,7 +24,7 @@ public class PunishedPlayerLockupEvent extends PunishedPlayerEvent implements Ca
|
|||||||
* @param punishedPlayer The player who was punished
|
* @param punishedPlayer The player who was punished
|
||||||
* @param lockedUp The new muted status
|
* @param lockedUp The new muted status
|
||||||
*/
|
*/
|
||||||
public PunishedPlayerLockupEvent(PlexPlayer punishedPlayer, boolean lockedUp)
|
public PunishedPlayerLockupEvent(IPlexPlayer punishedPlayer, boolean lockedUp)
|
||||||
{
|
{
|
||||||
super(punishedPlayer);
|
super(punishedPlayer);
|
||||||
this.lockedUp = lockedUp;
|
this.lockedUp = lockedUp;
|
@ -1,6 +1,6 @@
|
|||||||
package dev.plex.event;
|
package dev.plex.api.event;
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.api.player.IPlexPlayer;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -24,7 +24,7 @@ public class PunishedPlayerMuteEvent extends PunishedPlayerEvent implements Canc
|
|||||||
* @param punishedPlayer The player who was punished
|
* @param punishedPlayer The player who was punished
|
||||||
* @param muted The new muted status
|
* @param muted The new muted status
|
||||||
*/
|
*/
|
||||||
public PunishedPlayerMuteEvent(PlexPlayer punishedPlayer, boolean muted)
|
public PunishedPlayerMuteEvent(IPlexPlayer punishedPlayer, boolean muted)
|
||||||
{
|
{
|
||||||
super(punishedPlayer);
|
super(punishedPlayer);
|
||||||
this.muted = muted;
|
this.muted = muted;
|
@ -0,0 +1,32 @@
|
|||||||
|
package dev.plex.api.permission;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface IPermissionHandler
|
||||||
|
{
|
||||||
|
default boolean hasPermission(@NotNull Player player, @Nullable String permission)
|
||||||
|
{
|
||||||
|
if (permission == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return player.hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean hasPermission(@NotNull OfflinePlayer player, @Nullable String permission)
|
||||||
|
{
|
||||||
|
if (permission == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (player.isOnline() && Bukkit.getPlayer(player.getUniqueId()) != null)
|
||||||
|
{
|
||||||
|
return Bukkit.getPlayer(player.getUniqueId()).hasPermission(permission);
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException("Not implemented yet");
|
||||||
|
}
|
||||||
|
}
|
67
api/src/main/java/dev/plex/api/player/IPlexPlayer.java
Normal file
67
api/src/main/java/dev/plex/api/player/IPlexPlayer.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package dev.plex.api.player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
|
||||||
|
public interface IPlexPlayer
|
||||||
|
{
|
||||||
|
String getId();
|
||||||
|
|
||||||
|
UUID getUuid();
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
Player getPlayer();
|
||||||
|
|
||||||
|
void setPlayer(Player player);
|
||||||
|
|
||||||
|
String getLoginMessage();
|
||||||
|
|
||||||
|
void setLoginMessage(String message);
|
||||||
|
|
||||||
|
String getPrefix();
|
||||||
|
|
||||||
|
void setPrefix(String prefix);
|
||||||
|
|
||||||
|
boolean isVanished();
|
||||||
|
|
||||||
|
void setVanished(boolean vanished);
|
||||||
|
|
||||||
|
boolean isCommandSpy();
|
||||||
|
|
||||||
|
void setCommandSpy(boolean commandSpy);
|
||||||
|
|
||||||
|
boolean isFrozen();
|
||||||
|
|
||||||
|
void setFrozen(boolean frozen);
|
||||||
|
|
||||||
|
boolean isMuted();
|
||||||
|
|
||||||
|
void setMuted(boolean muted);
|
||||||
|
|
||||||
|
boolean isLockedUp();
|
||||||
|
|
||||||
|
void setLockedUp(boolean lockedUp);
|
||||||
|
|
||||||
|
boolean isAdminActive();
|
||||||
|
|
||||||
|
void setAdminActive(boolean active);
|
||||||
|
|
||||||
|
long getCoins();
|
||||||
|
|
||||||
|
void setCoins(long coins);
|
||||||
|
|
||||||
|
String getRank();
|
||||||
|
|
||||||
|
void setRank(String rank);
|
||||||
|
|
||||||
|
List<String> getIps();
|
||||||
|
|
||||||
|
void setIps(List<String> ips);
|
||||||
|
|
||||||
|
PermissionAttachment getPermissionAttachment();
|
||||||
|
|
||||||
|
void setPermissionAttachment(PermissionAttachment attachment);
|
||||||
|
}
|
30
api/src/main/java/dev/plex/api/plugin/PlexPlugin.java
Normal file
30
api/src/main/java/dev/plex/api/plugin/PlexPlugin.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package dev.plex.api.plugin;
|
||||||
|
|
||||||
|
import dev.plex.api.chat.IChatHandler;
|
||||||
|
import dev.plex.api.permission.IPermissionHandler;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public abstract class PlexPlugin extends JavaPlugin
|
||||||
|
{
|
||||||
|
@Setter(AccessLevel.NONE)
|
||||||
|
private static PlexPlugin plugin;
|
||||||
|
|
||||||
|
private IChatHandler chatHandler;
|
||||||
|
private IPermissionHandler permissionHandler;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad()
|
||||||
|
{
|
||||||
|
plugin = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlexPlugin get()
|
||||||
|
{
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
}
|
26
api/src/main/java/dev/plex/api/rank/IRank.java
Normal file
26
api/src/main/java/dev/plex/api/rank/IRank.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package dev.plex.api.rank;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public interface IRank<T>
|
||||||
|
{
|
||||||
|
int getLevel();
|
||||||
|
|
||||||
|
String getLoginMessage();
|
||||||
|
|
||||||
|
void setLoginMessage(String message);
|
||||||
|
|
||||||
|
String getReadable();
|
||||||
|
|
||||||
|
Component getPrefix();
|
||||||
|
|
||||||
|
void setPrefix(String prefix);
|
||||||
|
|
||||||
|
NamedTextColor getColor();
|
||||||
|
|
||||||
|
boolean isAtLeast(T rank);
|
||||||
|
|
||||||
|
JSONObject toJSON();
|
||||||
|
}
|
179
build.gradle
179
build.gradle
@ -1,146 +1,73 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "java"
|
id "java"
|
||||||
id "maven-publish"
|
id "maven-publish"
|
||||||
id "net.minecrell.plugin-yml.bukkit" version "0.5.1"
|
|
||||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
maven {
|
|
||||||
url = uri("https://papermc.io/repo/repository/maven-public/")
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url = uri("https://repository.apache.org/content/repositories/snapshots/")
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url = uri("https://repo.maven.apache.org/maven2/")
|
|
||||||
}
|
|
||||||
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
library "org.projectlombok:lombok:1.18.22"
|
|
||||||
annotationProcessor "org.projectlombok:lombok:1.18.22"
|
|
||||||
library "org.json:json:20220320"
|
|
||||||
library "commons-io:commons-io:2.11.0"
|
|
||||||
library "dev.morphia.morphia:morphia-core:2.2.6"
|
|
||||||
library "redis.clients:jedis:4.2.1"
|
|
||||||
library "org.mariadb.jdbc:mariadb-java-client:3.0.4"
|
|
||||||
library "com.zaxxer:HikariCP:5.0.1"
|
|
||||||
library "org.apache.httpcomponents:httpclient:4.5.13"
|
|
||||||
library "org.apache.commons:commons-lang3:3.12.0"
|
|
||||||
library "org.apache.maven.resolver:maven-resolver-api:1.7.3"
|
|
||||||
library "org.apache.maven.resolver:maven-resolver-impl:1.7.3"
|
|
||||||
library "org.apache.maven.resolver:maven-resolver-connector-basic:1.7.3"
|
|
||||||
library "org.apache.maven.resolver:maven-resolver-transport-http:1.7.3"
|
|
||||||
library "org.apache.maven:maven-resolver-provider:3.8.5"
|
|
||||||
library "org.eclipse.jetty:jetty-server:11.0.9"
|
|
||||||
library "org.eclipse.jetty:jetty-servlet:11.0.9"
|
|
||||||
library "org.eclipse.jetty:jetty-proxy:11.0.9"
|
|
||||||
library "com.google.code.gson:gson:2.9.0"
|
|
||||||
compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT"
|
|
||||||
implementation "org.bstats:bstats-base:3.0.0"
|
|
||||||
implementation "org.bstats:bstats-bukkit:3.0.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "dev.plex"
|
group = "dev.plex"
|
||||||
version = "1.0"
|
version = "1.1"
|
||||||
description = "Plex"
|
description = "Plex"
|
||||||
|
|
||||||
shadowJar {
|
subprojects {
|
||||||
archiveClassifier.set("")
|
apply plugin: "java"
|
||||||
relocate "org.bstats", "dev.plex"
|
apply plugin: "maven-publish"
|
||||||
}
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
|
|
||||||
bukkit {
|
|
||||||
name = "Plex"
|
|
||||||
version = rootProject.version
|
|
||||||
description = "Plex provides a new experience for freedom servers."
|
|
||||||
main = "dev.plex.Plex"
|
|
||||||
website = "https://plex.us.org"
|
|
||||||
authors = ["Telesphoreo", "taahanis", "super"]
|
|
||||||
apiVersion = "1.18"
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGitHash() {
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
|
||||||
try {
|
|
||||||
exec {
|
|
||||||
commandLine "git", "rev-parse", "--short", "HEAD"
|
|
||||||
standardOutput = stdout
|
|
||||||
ignoreExitValue = true
|
|
||||||
}
|
|
||||||
} catch (GradleException e) {
|
|
||||||
logger.error("Couldn't determine Git head because Git is not installed. " + e.getMessage())
|
|
||||||
}
|
|
||||||
return stdout.size() > 0 ? stdout.toString().trim() : "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
String getBuildNumber() {
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
|
||||||
try {
|
|
||||||
exec {
|
|
||||||
commandLine "git", "rev-list", "HEAD", "--count"
|
|
||||||
standardOutput = stdout
|
|
||||||
ignoreExitValue = true
|
|
||||||
}
|
|
||||||
} catch (GradleException e) {
|
|
||||||
logger.error("Couldn't determine build number because Git is not installed. " + e.getMessage())
|
|
||||||
}
|
|
||||||
return stdout.size() ? stdout.toString().trim() + " (local)" : "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
static def getDate() {
|
|
||||||
return new Date().format("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a")
|
|
||||||
}
|
|
||||||
|
|
||||||
task buildProperties {
|
|
||||||
ant.propertyfile(file: "$project.rootDir/src/main/resources/build.properties") {
|
|
||||||
entry(key: "buildAuthor", default: System.getenv("JENKINS_URL") != null ? "jenkins" : "unknown")
|
|
||||||
entry(key: "buildNumber", value: System.getenv("JENKINS_URL") != null ? System.getenv("BUILD_NUMBER") + " (Jenkins)" : getBuildNumber())
|
|
||||||
entry(key: "buildDate", value: getDate())
|
|
||||||
entry(key: "buildHead", value: getGitHash())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
maven(MavenPublication) {
|
|
||||||
from(components.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
|
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||||
def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
}
|
||||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
|
||||||
credentials {
|
maven {
|
||||||
username = System.getenv("plexUser")
|
url = uri("https://repository.apache.org/content/repositories/snapshots/")
|
||||||
password = System.getenv("plexPassword")
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri("https://repo.maven.apache.org/maven2/")
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri("https://jitpack.io")
|
||||||
|
content {
|
||||||
|
includeGroup("com.github.MilkBowl")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
|
||||||
|
def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
||||||
|
url = rootProject.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
||||||
|
credentials {
|
||||||
|
username = System.getenv("plexUser")
|
||||||
|
password = System.getenv("plexPassword")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
clean {
|
||||||
options.encoding = "UTF-8"
|
dependsOn(":api:clean")
|
||||||
|
dependsOn(":server:clean")
|
||||||
|
dependsOn(":proxy:clean")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
task copyJars(type: Copy, dependsOn: subprojects.jar) {
|
||||||
build {
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
dependsOn(shadowJar)
|
from(subprojects.jar)
|
||||||
finalizedBy(buildProperties)
|
from(subprojects.shadowJar)
|
||||||
}
|
into project.file('build/libs')
|
||||||
|
|
||||||
javadoc {
|
|
||||||
options.memberLevel = JavadocMemberLevel.PRIVATE
|
|
||||||
}
|
|
||||||
}
|
}
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
46
proxy/build.gradle.kts
Normal file
46
proxy/build.gradle.kts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
plugins {
|
||||||
|
id("net.kyori.blossom") version "1.2.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = rootProject.group
|
||||||
|
version = rootProject.version
|
||||||
|
description = "Plex-Velocity"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.getByName<Jar>("jar") {
|
||||||
|
archiveBaseName.set("Plex-Velocity")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
jar {
|
||||||
|
finalizedBy(rootProject.tasks["copyJars"])
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blossom {
|
||||||
|
replaceToken("@version@", rootProject.version)
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("maven") {
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("org.projectlombok:lombok:1.18.24")
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.24")
|
||||||
|
compileOnly("org.json:json:20220320")
|
||||||
|
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
||||||
|
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
||||||
|
implementation(project(":api"))
|
||||||
|
}
|
81
proxy/src/main/java/dev/plex/Plex.java
Normal file
81
proxy/src/main/java/dev/plex/Plex.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
package dev.plex;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import dev.plex.config.TomlConfig;
|
||||||
|
import dev.plex.handlers.ListenerHandler;
|
||||||
|
import dev.plex.settings.ServerSettings;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Credits for TOML library go to https://github.com/mwanji/toml4j
|
||||||
|
* I was unable to add it back to the package without it glitching, so
|
||||||
|
* I kept it in a separate package.
|
||||||
|
* <p>
|
||||||
|
* Modifications: Properly indent arrays in TOML as well as only append
|
||||||
|
* missing object fields into the file
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Plugin(
|
||||||
|
name = "Plex",
|
||||||
|
id = "plex",
|
||||||
|
version = "@version@",
|
||||||
|
url = "https://plex.us.org",
|
||||||
|
description = "Plex provides a new experience for freedom servers.",
|
||||||
|
authors = {"Telesphoreo", "Taah"}
|
||||||
|
)
|
||||||
|
@Getter
|
||||||
|
public class Plex
|
||||||
|
{
|
||||||
|
private static Plex plugin;
|
||||||
|
|
||||||
|
public final ProxyServer server;
|
||||||
|
private final Logger logger;
|
||||||
|
private final File dataFolder;
|
||||||
|
|
||||||
|
private TomlConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Plex(ProxyServer server, Logger logger, @DataDirectory Path folder)
|
||||||
|
{
|
||||||
|
plugin = this;
|
||||||
|
this.server = server;
|
||||||
|
this.logger = logger;
|
||||||
|
this.dataFolder = folder.toFile();
|
||||||
|
if (!dataFolder.exists())
|
||||||
|
{
|
||||||
|
dataFolder.mkdir();
|
||||||
|
}
|
||||||
|
PlexLog.log("Enabling Plex-Velocity");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStart(ProxyInitializeEvent event)
|
||||||
|
{
|
||||||
|
this.config = new TomlConfig("config.toml");
|
||||||
|
this.config.setOnCreate(toml ->
|
||||||
|
{
|
||||||
|
PlexLog.log("Created configuration 'config.toml'");
|
||||||
|
});
|
||||||
|
this.config.setOnLoad(toml ->
|
||||||
|
{
|
||||||
|
PlexLog.log("Loaded configuration 'config.toml'");
|
||||||
|
});
|
||||||
|
this.config.create(true);
|
||||||
|
this.config.write(new ServerSettings());
|
||||||
|
new ListenerHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Plex get()
|
||||||
|
{
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
}
|
102
proxy/src/main/java/dev/plex/command/PlexCommand.java
Normal file
102
proxy/src/main/java/dev/plex/command/PlexCommand.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package dev.plex.command;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class PlexCommand implements SimpleCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the instance of the plugin
|
||||||
|
*/
|
||||||
|
protected static Plex plugin = Plex.get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parameters for the command
|
||||||
|
*/
|
||||||
|
private final CommandParameters params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The permissions for the command
|
||||||
|
*/
|
||||||
|
private final CommandPermissions perms;
|
||||||
|
/**
|
||||||
|
* Required command source fetched from the permissions
|
||||||
|
*/
|
||||||
|
private final RequiredCommandSource commandSource;
|
||||||
|
|
||||||
|
public PlexCommand()
|
||||||
|
{
|
||||||
|
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||||
|
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||||
|
this.commandSource = this.perms.source();
|
||||||
|
|
||||||
|
CommandMeta.Builder meta = plugin.getServer().getCommandManager().metaBuilder(this.params.name());
|
||||||
|
meta.aliases(this.params.aliases());
|
||||||
|
meta.plugin(Plex.get());
|
||||||
|
plugin.getServer().getCommandManager().register(meta.build(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Component execute(@NotNull CommandSource source, @Nullable Player player, @NotNull String[] args);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Invocation invocation)
|
||||||
|
{
|
||||||
|
if (!matches(invocation.alias()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandSource == RequiredCommandSource.CONSOLE && invocation.source() instanceof Player)
|
||||||
|
{
|
||||||
|
// sender.sendMessage(messageComponent("noPermissionInGame"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandSource == RequiredCommandSource.IN_GAME)
|
||||||
|
{
|
||||||
|
if (invocation.source() instanceof ConsoleCommandSource)
|
||||||
|
{
|
||||||
|
// send(sender, messageComponent("noPermissionConsole"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!perms.permission().isEmpty())
|
||||||
|
{
|
||||||
|
if (!invocation.source().hasPermission(perms.permission()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component component = this.execute(invocation.source(), invocation.source() instanceof ConsoleCommandSource ? null : (Player) invocation.source(), invocation.arguments());
|
||||||
|
if (component != null)
|
||||||
|
{
|
||||||
|
send(invocation.source(), component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matches(String label)
|
||||||
|
{
|
||||||
|
if (params.name().equalsIgnoreCase(label))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return Arrays.stream(params.aliases()).anyMatch(s -> s.equalsIgnoreCase(label));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void send(Audience audience, Component component)
|
||||||
|
{
|
||||||
|
audience.sendMessage(component);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package dev.plex.command.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage for a command's parameters
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface CommandParameters
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name
|
||||||
|
*
|
||||||
|
* @return Name of the command
|
||||||
|
*/
|
||||||
|
String name();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The description
|
||||||
|
*
|
||||||
|
* @return Description of the command
|
||||||
|
*/
|
||||||
|
String description() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The usage (optional)
|
||||||
|
*
|
||||||
|
* @return The usage of the command
|
||||||
|
*/
|
||||||
|
String usage() default "/<command>";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The aliases (optional)
|
||||||
|
*
|
||||||
|
* @return The aliases of the command
|
||||||
|
*/
|
||||||
|
String[] aliases() default {};
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package dev.plex.command.annotation;
|
||||||
|
|
||||||
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage for the command's permissions
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface CommandPermissions
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Required command source
|
||||||
|
*
|
||||||
|
* @return The required command source of the command
|
||||||
|
* @see RequiredCommandSource
|
||||||
|
*/
|
||||||
|
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The permission
|
||||||
|
*
|
||||||
|
* @return Permission of the command
|
||||||
|
*/
|
||||||
|
String permission() default ""; // No idea what to put here
|
||||||
|
}
|
99
proxy/src/main/java/dev/plex/config/TomlConfig.java
Normal file
99
proxy/src/main/java/dev/plex/config/TomlConfig.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package dev.plex.config;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.toml.Toml;
|
||||||
|
import dev.plex.toml.TomlWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class TomlConfig
|
||||||
|
{
|
||||||
|
private final File file;
|
||||||
|
private Toml toml;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Consumer<Toml> onCreate;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Consumer<Toml> onLoad;
|
||||||
|
|
||||||
|
public TomlConfig(String fileName)
|
||||||
|
{
|
||||||
|
this.file = new File(Plex.get().getDataFolder(), fileName);
|
||||||
|
this.toml = new Toml();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void create(boolean loadFromFile)
|
||||||
|
{
|
||||||
|
if (!this.file.exists())
|
||||||
|
{
|
||||||
|
if (loadFromFile)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.copy(Plex.get().getClass().getResourceAsStream("/" + this.file.getName()), this.file.toPath());
|
||||||
|
this.load();
|
||||||
|
if (this.onCreate != null)
|
||||||
|
{
|
||||||
|
this.onCreate.accept(this.toml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.file.createNewFile();
|
||||||
|
this.load();
|
||||||
|
if (this.onCreate != null)
|
||||||
|
{
|
||||||
|
this.onCreate.accept(this.toml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
this.toml = new Toml().read(this.file);
|
||||||
|
if (onLoad != null)
|
||||||
|
{
|
||||||
|
this.onLoad.accept(this.toml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T as(Class<T> clazz)
|
||||||
|
{
|
||||||
|
return this.toml.to(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void write(T object)
|
||||||
|
{
|
||||||
|
TomlWriter writer = new TomlWriter.Builder()
|
||||||
|
.indentValuesBy(2)
|
||||||
|
.build();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
writer.write(object, this.file);
|
||||||
|
this.load();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
proxy/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
32
proxy/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package dev.plex.handlers;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.ReflectionsUtil;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ListenerHandler
|
||||||
|
{
|
||||||
|
public ListenerHandler()
|
||||||
|
{
|
||||||
|
Set<Class<? extends PlexListener>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", PlexListener.class);
|
||||||
|
List<PlexListener> listeners = Lists.newArrayList();
|
||||||
|
|
||||||
|
listenerSet.forEach(clazz ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
listeners.add(clazz.getConstructor().newInstance());
|
||||||
|
}
|
||||||
|
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||||
|
NoSuchMethodException ex)
|
||||||
|
{
|
||||||
|
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a listener!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PlexLog.log(String.format("Registered %s listeners from %s classes!", listeners.size(), listenerSet.size()));
|
||||||
|
}
|
||||||
|
}
|
13
proxy/src/main/java/dev/plex/listener/PlexListener.java
Normal file
13
proxy/src/main/java/dev/plex/listener/PlexListener.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package dev.plex.listener;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
|
||||||
|
public class PlexListener
|
||||||
|
{
|
||||||
|
protected final Plex plugin = Plex.get();
|
||||||
|
|
||||||
|
public PlexListener()
|
||||||
|
{
|
||||||
|
Plex.get().getServer().getEventManager().register(Plex.get(), this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
public class ConnectionListener extends PlexListener
|
||||||
|
{
|
||||||
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
|
public void onPlayerJoin(ServerConnectedEvent event)
|
||||||
|
{
|
||||||
|
if (event.getPreviousServer().isPresent())
|
||||||
|
{
|
||||||
|
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<#ffbf00>o<dark_gray>] <yellow>"
|
||||||
|
+ event.getPlayer().getUsername() + " switched from " + event.getPreviousServer().get().getServerInfo().getName()
|
||||||
|
+ " to " + event.getServer().getServerInfo().getName()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<green>+<dark_gray>] <yellow>"
|
||||||
|
+ event.getPlayer().getUsername() + " joined server " + event.getServer().getServerInfo().getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
|
public void onPlayerLeave(DisconnectEvent event)
|
||||||
|
{
|
||||||
|
if (event.getPlayer().getCurrentServer().isPresent())
|
||||||
|
{
|
||||||
|
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<red>-<dark_gray>] <yellow>"
|
||||||
|
+ event.getPlayer().getUsername() + " left server " +
|
||||||
|
event.getPlayer().getCurrentServer().get().getServerInfo().getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component miniMessage(String message)
|
||||||
|
{
|
||||||
|
return MiniMessage.miniMessage().deserialize(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||||
|
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.settings.ServerSettings;
|
||||||
|
import dev.plex.util.RandomUtil;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
public class ServerListener extends PlexListener
|
||||||
|
{
|
||||||
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
|
public void onPing(ProxyPingEvent event)
|
||||||
|
{
|
||||||
|
String baseMotd = plugin.getConfig().as(ServerSettings.class).getServer().getMotd().get(ThreadLocalRandom.current().nextInt(plugin.getConfig().as(ServerSettings.class).getServer().getMotd().size()));
|
||||||
|
baseMotd = baseMotd.replace("\\n", "\n");
|
||||||
|
baseMotd = baseMotd.replace("%servername%", plugin.getConfig().as(ServerSettings.class).getServer().getName());
|
||||||
|
baseMotd = baseMotd.replace("%mcversion%", plugin.getServer().getVersion().getVersion().split(" ")[0]);
|
||||||
|
baseMotd = baseMotd.replace("%randomgradient%", "<gradient:" + RandomUtil.getRandomColor().toString() + ":" + RandomUtil.getRandomColor().toString() + ">");
|
||||||
|
|
||||||
|
ServerPing.Builder builder = event.getPing().asBuilder();
|
||||||
|
|
||||||
|
if (plugin.getConfig().as(ServerSettings.class).getServer().isColorizeMotd())
|
||||||
|
{
|
||||||
|
AtomicReference<Component> motd = new AtomicReference<>(Component.empty());
|
||||||
|
for (final String word : baseMotd.split(" "))
|
||||||
|
{
|
||||||
|
motd.set(motd.get().append(Component.text(word).color(RandomUtil.getRandomColor())));
|
||||||
|
motd.set(motd.get().append(Component.space()));
|
||||||
|
}
|
||||||
|
builder.description(motd.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.description(MiniMessage.miniMessage().deserialize(baseMotd));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.samplePlayers(plugin.getConfig().as(ServerSettings.class).getServer().getSample().stream().map(s -> new ServerPing.SamplePlayer(convertColorCodes(s), UUID.randomUUID())).toArray(ServerPing.SamplePlayer[]::new));
|
||||||
|
builder.onlinePlayers(plugin.getServer().getPlayerCount() + plugin.getConfig().as(ServerSettings.class).getServer().getAddPlayerCount());
|
||||||
|
if (plugin.getConfig().as(ServerSettings.class).getServer().isPlusOneMaxPlayer())
|
||||||
|
{
|
||||||
|
builder.maximumPlayers(builder.getOnlinePlayers() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setPing(builder.build());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertColorCodes(String code)
|
||||||
|
{
|
||||||
|
Matcher matcher = Pattern.compile("[&][0-9a-fk-or]{1}").matcher(code);
|
||||||
|
return matcher.replaceAll(matchResult -> "§" + matcher.group().substring(1));
|
||||||
|
}
|
||||||
|
}
|
27
proxy/src/main/java/dev/plex/settings/ServerSettings.java
Normal file
27
proxy/src/main/java/dev/plex/settings/ServerSettings.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package dev.plex.settings;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class ServerSettings
|
||||||
|
{
|
||||||
|
private final Server server = new Server();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Server
|
||||||
|
{
|
||||||
|
private String name = "Server";
|
||||||
|
private List<String> motd = Lists.newArrayList("%randomgradient%%servername% - %mcversion%", "Another motd");
|
||||||
|
private boolean colorizeMotd = false;
|
||||||
|
private boolean debug = false;
|
||||||
|
private final List<String> sample = Lists.newArrayList("example", "example");
|
||||||
|
@SerializedName(value = "add-player-count")
|
||||||
|
private int addPlayerCount = 0;
|
||||||
|
@SerializedName(value = "plus-one-max-count")
|
||||||
|
private boolean plusOneMaxPlayer = true;
|
||||||
|
}
|
||||||
|
}
|
108
proxy/src/main/java/dev/plex/toml/ArrayValueReader.java
Normal file
108
proxy/src/main/java/dev/plex/toml/ArrayValueReader.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class ArrayValueReader implements ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final ArrayValueReader ARRAY_VALUE_READER = new ArrayValueReader();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("[");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int startIndex = index.get();
|
||||||
|
List<Object> arrayItems = new ArrayList<Object>();
|
||||||
|
boolean terminated = false;
|
||||||
|
boolean inComment = false;
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
|
||||||
|
for (int i = index.incrementAndGet(); i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == '#' && !inComment)
|
||||||
|
{
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
else if (c == '\n')
|
||||||
|
{
|
||||||
|
inComment = false;
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
else if (inComment || Character.isWhitespace(c) || c == ',')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == '[')
|
||||||
|
{
|
||||||
|
Object converted = read(s, index, context);
|
||||||
|
if (converted instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
errors.add((dev.plex.toml.Results.Errors) converted);
|
||||||
|
}
|
||||||
|
else if (!isHomogenousArray(converted, arrayItems))
|
||||||
|
{
|
||||||
|
errors.heterogenous(context.identifier.getName(), line.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arrayItems.add(converted);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == ']')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Object converted = ValueReaders.VALUE_READERS.convert(s, index, context);
|
||||||
|
if (converted instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
errors.add((dev.plex.toml.Results.Errors) converted);
|
||||||
|
}
|
||||||
|
else if (!isHomogenousArray(converted, arrayItems))
|
||||||
|
{
|
||||||
|
errors.heterogenous(context.identifier.getName(), line.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arrayItems.add(converted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!terminated)
|
||||||
|
{
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex), startLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.hasErrors())
|
||||||
|
{
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrayItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isHomogenousArray(Object o, List<?> values)
|
||||||
|
{
|
||||||
|
return values.isEmpty() || values.get(0).getClass().isAssignableFrom(o.getClass()) || o.getClass().isAssignableFrom(values.get(0).getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
82
proxy/src/main/java/dev/plex/toml/ArrayValueWriter.java
Normal file
82
proxy/src/main/java/dev/plex/toml/ArrayValueWriter.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||||
|
|
||||||
|
public abstract class ArrayValueWriter implements dev.plex.toml.ValueWriter
|
||||||
|
{
|
||||||
|
static protected boolean isArrayish(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof Collection || value.getClass().isArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isArrayOfPrimitive(Object array)
|
||||||
|
{
|
||||||
|
Object first = peek(array);
|
||||||
|
if (first != null)
|
||||||
|
{
|
||||||
|
dev.plex.toml.ValueWriter valueWriter = WRITERS.findWriterFor(first);
|
||||||
|
return valueWriter.isPrimitiveType() || isArrayish(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected Collection<?> normalize(Object value)
|
||||||
|
{
|
||||||
|
Collection<Object> collection;
|
||||||
|
|
||||||
|
if (value.getClass().isArray())
|
||||||
|
{
|
||||||
|
// Arrays.asList() interprets an array as a single element,
|
||||||
|
// so convert it to a list by hand
|
||||||
|
collection = new ArrayList<Object>(Array.getLength(value));
|
||||||
|
for (int i = 0; i < Array.getLength(value); i++)
|
||||||
|
{
|
||||||
|
Object elem = Array.get(value, i);
|
||||||
|
collection.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
collection = (Collection<Object>) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object peek(Object value)
|
||||||
|
{
|
||||||
|
if (value.getClass().isArray())
|
||||||
|
{
|
||||||
|
if (Array.getLength(value) > 0)
|
||||||
|
{
|
||||||
|
return Array.get(value, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Collection<?> collection = (Collection<?>) value;
|
||||||
|
if (collection.size() > 0)
|
||||||
|
{
|
||||||
|
return collection.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
||||||
|
class BooleanValueReaderWriter implements ValueReader, ValueWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
static final BooleanValueReaderWriter BOOLEAN_VALUE_READER_WRITER = new BooleanValueReaderWriter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("true") || s.startsWith("false");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
s = s.substring(index.get());
|
||||||
|
Boolean b = s.startsWith("true") ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
|
||||||
|
int endIndex = b == Boolean.TRUE ? 4 : 5;
|
||||||
|
|
||||||
|
index.addAndGet(endIndex - 1);
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
context.write(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BooleanValueReaderWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "boolean";
|
||||||
|
}
|
||||||
|
}
|
152
proxy/src/main/java/dev/plex/toml/Container.java
Normal file
152
proxy/src/main/java/dev/plex/toml/Container.java
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class Container
|
||||||
|
{
|
||||||
|
|
||||||
|
abstract boolean accepts(String key);
|
||||||
|
|
||||||
|
abstract void put(String key, Object value);
|
||||||
|
|
||||||
|
abstract Object get(String key);
|
||||||
|
|
||||||
|
abstract boolean isImplicit();
|
||||||
|
|
||||||
|
static class Table extends Container
|
||||||
|
{
|
||||||
|
private final Map<String, Object> values = new HashMap<String, Object>();
|
||||||
|
final String name;
|
||||||
|
final boolean implicit;
|
||||||
|
|
||||||
|
Table()
|
||||||
|
{
|
||||||
|
this(null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table(String name)
|
||||||
|
{
|
||||||
|
this(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table(String tableName, boolean implicit)
|
||||||
|
{
|
||||||
|
this.name = tableName;
|
||||||
|
this.implicit = implicit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean accepts(String key)
|
||||||
|
{
|
||||||
|
return !values.containsKey(key) || values.get(key) instanceof TableArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void put(String key, Object value)
|
||||||
|
{
|
||||||
|
values.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Object get(String key)
|
||||||
|
{
|
||||||
|
return values.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isImplicit()
|
||||||
|
{
|
||||||
|
return implicit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This modifies the Table's internal data structure, such that it is no longer usable.
|
||||||
|
* <p>
|
||||||
|
* Therefore, this method must only be called when all data has been gathered.
|
||||||
|
*
|
||||||
|
* @return A Map-and-List-based of the TOML data
|
||||||
|
*/
|
||||||
|
Map<String, Object> consume()
|
||||||
|
{
|
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet())
|
||||||
|
{
|
||||||
|
if (entry.getValue() instanceof Table)
|
||||||
|
{
|
||||||
|
entry.setValue(((Table) entry.getValue()).consume());
|
||||||
|
}
|
||||||
|
else if (entry.getValue() instanceof TableArray)
|
||||||
|
{
|
||||||
|
entry.setValue(((TableArray) entry.getValue()).getValues());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return values.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TableArray extends Container
|
||||||
|
{
|
||||||
|
private final List<Table> values = new ArrayList<Table>();
|
||||||
|
|
||||||
|
TableArray()
|
||||||
|
{
|
||||||
|
values.add(new Table());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean accepts(String key)
|
||||||
|
{
|
||||||
|
return getCurrent().accepts(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void put(String key, Object value)
|
||||||
|
{
|
||||||
|
values.add((Table) value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Object get(String key)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isImplicit()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, Object>> getValues()
|
||||||
|
{
|
||||||
|
ArrayList<Map<String, Object>> unwrappedValues = new ArrayList<Map<String, Object>>();
|
||||||
|
for (Table table : values)
|
||||||
|
{
|
||||||
|
unwrappedValues.add(table.consume());
|
||||||
|
}
|
||||||
|
return unwrappedValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
Table getCurrent()
|
||||||
|
{
|
||||||
|
return values.get(values.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return values.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
22
proxy/src/main/java/dev/plex/toml/Context.java
Normal file
22
proxy/src/main/java/dev/plex/toml/Context.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class Context
|
||||||
|
{
|
||||||
|
final dev.plex.toml.Identifier identifier;
|
||||||
|
final AtomicInteger line;
|
||||||
|
final Results.Errors errors;
|
||||||
|
|
||||||
|
public Context(dev.plex.toml.Identifier identifier, AtomicInteger line, Results.Errors errors)
|
||||||
|
{
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.line = line;
|
||||||
|
this.errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Context with(dev.plex.toml.Identifier identifier)
|
||||||
|
{
|
||||||
|
return new Context(identifier, line, errors);
|
||||||
|
}
|
||||||
|
}
|
26
proxy/src/main/java/dev/plex/toml/DatePolicy.java
Normal file
26
proxy/src/main/java/dev/plex/toml/DatePolicy.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
public class DatePolicy
|
||||||
|
{
|
||||||
|
|
||||||
|
private final TimeZone timeZone;
|
||||||
|
private final boolean showFractionalSeconds;
|
||||||
|
|
||||||
|
DatePolicy(TimeZone timeZone, boolean showFractionalSeconds)
|
||||||
|
{
|
||||||
|
this.timeZone = timeZone;
|
||||||
|
this.showFractionalSeconds = showFractionalSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeZone getTimeZone()
|
||||||
|
{
|
||||||
|
return timeZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isShowFractionalSeconds()
|
||||||
|
{
|
||||||
|
return showFractionalSeconds;
|
||||||
|
}
|
||||||
|
}
|
204
proxy/src/main/java/dev/plex/toml/DateValueReaderWriter.java
Normal file
204
proxy/src/main/java/dev/plex/toml/DateValueReaderWriter.java
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class DateValueReaderWriter implements ValueReader, ValueWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
static final DateValueReaderWriter DATE_VALUE_READER_WRITER = new DateValueReaderWriter();
|
||||||
|
static final DateValueReaderWriter DATE_PARSER_JDK_6 = new DateConverterJdk6();
|
||||||
|
private static final Pattern DATE_REGEX = Pattern.compile("(\\d{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9])(\\.\\d*)?(Z|(?:[+\\-]\\d{2}:\\d{2}))(.*)");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
if (s.length() < 5)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (i < 4)
|
||||||
|
{
|
||||||
|
if (!Character.isDigit(c))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c != '-')
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String original, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = index.get(); i < original.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = original.charAt(i);
|
||||||
|
if (Character.isDigit(c) || c == '-' || c == '+' || c == ':' || c == '.' || c == 'T' || c == 'Z')
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index.decrementAndGet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = sb.toString();
|
||||||
|
Matcher matcher = DATE_REGEX.matcher(s);
|
||||||
|
|
||||||
|
if (!matcher.matches())
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), s, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
String dateString = matcher.group(1);
|
||||||
|
String zone = matcher.group(3);
|
||||||
|
String fractionalSeconds = matcher.group(2);
|
||||||
|
String format = "yyyy-MM-dd'T'HH:mm:ss";
|
||||||
|
if (fractionalSeconds != null && !fractionalSeconds.isEmpty())
|
||||||
|
{
|
||||||
|
format += ".SSS";
|
||||||
|
dateString += fractionalSeconds;
|
||||||
|
}
|
||||||
|
format += "Z";
|
||||||
|
if ("Z".equals(zone))
|
||||||
|
{
|
||||||
|
dateString += "+0000";
|
||||||
|
}
|
||||||
|
else if (zone.contains(":"))
|
||||||
|
{
|
||||||
|
dateString += zone.replace(":", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
|
||||||
|
dateFormat.setLenient(false);
|
||||||
|
return dateFormat.parse(dateString);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), s, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
DateFormat formatter = getFormatter(context.getDatePolicy());
|
||||||
|
context.write(formatter.format(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateFormat getFormatter(DatePolicy datePolicy)
|
||||||
|
{
|
||||||
|
boolean utc = "UTC".equals(datePolicy.getTimeZone().getID());
|
||||||
|
String format;
|
||||||
|
|
||||||
|
if (utc && datePolicy.isShowFractionalSeconds())
|
||||||
|
{
|
||||||
|
format = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
|
}
|
||||||
|
else if (utc)
|
||||||
|
{
|
||||||
|
format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||||
|
}
|
||||||
|
else if (datePolicy.isShowFractionalSeconds())
|
||||||
|
{
|
||||||
|
format = getTimeZoneAndFractionalSecondsFormat();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format = getTimeZoneFormat();
|
||||||
|
}
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(format);
|
||||||
|
formatter.setTimeZone(datePolicy.getTimeZone());
|
||||||
|
|
||||||
|
return formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTimeZoneFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ssXXX";
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTimeZoneAndFractionalSecondsFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateValueReaderWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateConverterJdk6 extends DateValueReaderWriter
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
DateFormat formatter = super.getFormatter(context.getDatePolicy());
|
||||||
|
String date = formatter.format(value);
|
||||||
|
|
||||||
|
if ("UTC".equals(context.getDatePolicy().getTimeZone().getID()))
|
||||||
|
{
|
||||||
|
context.write(date);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int insertionIndex = date.length() - 2;
|
||||||
|
context.write(date.substring(0, insertionIndex)).write(':').write(date.substring(insertionIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getTimeZoneAndFractionalSecondsFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getTimeZoneFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ssZ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "datetime";
|
||||||
|
}
|
||||||
|
}
|
341
proxy/src/main/java/dev/plex/toml/Identifier.java
Normal file
341
proxy/src/main/java/dev/plex/toml/Identifier.java
Normal file
@ -0,0 +1,341 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
public class Identifier
|
||||||
|
{
|
||||||
|
|
||||||
|
static final Identifier INVALID = new Identifier("", null);
|
||||||
|
|
||||||
|
private static final String ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_-";
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Type type;
|
||||||
|
|
||||||
|
static Identifier from(String name, Context context)
|
||||||
|
{
|
||||||
|
Type type;
|
||||||
|
boolean valid;
|
||||||
|
name = name.trim();
|
||||||
|
if (name.startsWith("[["))
|
||||||
|
{
|
||||||
|
type = Type.TABLE_ARRAY;
|
||||||
|
valid = isValidTableArray(name, context);
|
||||||
|
}
|
||||||
|
else if (name.startsWith("["))
|
||||||
|
{
|
||||||
|
type = Type.TABLE;
|
||||||
|
valid = isValidTable(name, context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
type = Type.KEY;
|
||||||
|
valid = isValidKey(name, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
return Identifier.INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Identifier(extractName(name), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Identifier(String name, Type type)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getBareName()
|
||||||
|
{
|
||||||
|
if (isKey())
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTable())
|
||||||
|
{
|
||||||
|
return name.substring(1, name.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name.substring(2, name.length() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isKey()
|
||||||
|
{
|
||||||
|
return type == Type.KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isTable()
|
||||||
|
{
|
||||||
|
return type == Type.TABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isTableArray()
|
||||||
|
{
|
||||||
|
return type == Type.TABLE_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Type
|
||||||
|
{
|
||||||
|
KEY, TABLE, TABLE_ARRAY
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String extractName(String raw)
|
||||||
|
{
|
||||||
|
boolean quoted = false;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = 0; i < raw.length(); i++)
|
||||||
|
{
|
||||||
|
char c = raw.charAt(i);
|
||||||
|
if (c == '"' && (i == 0 || raw.charAt(i - 1) != '\\'))
|
||||||
|
{
|
||||||
|
quoted = !quoted;
|
||||||
|
sb.append('"');
|
||||||
|
}
|
||||||
|
else if (quoted || !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidKey(String name, Context context)
|
||||||
|
{
|
||||||
|
if (name.trim().isEmpty())
|
||||||
|
{
|
||||||
|
context.errors.invalidKey(name, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean quoted = false;
|
||||||
|
for (int i = 0; i < name.length(); i++)
|
||||||
|
{
|
||||||
|
char c = name.charAt(i);
|
||||||
|
|
||||||
|
if (c == '"' && (i == 0 || name.charAt(i - 1) != '\\'))
|
||||||
|
{
|
||||||
|
if (!quoted && i > 0 && name.charAt(i - 1) != '.')
|
||||||
|
{
|
||||||
|
context.errors.invalidKey(name, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
quoted = !quoted;
|
||||||
|
}
|
||||||
|
else if (!quoted && (ALLOWED_CHARS.indexOf(c) == -1))
|
||||||
|
{
|
||||||
|
context.errors.invalidKey(name, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidTable(String name, Context context)
|
||||||
|
{
|
||||||
|
boolean valid = name.endsWith("]");
|
||||||
|
|
||||||
|
String trimmed = name.substring(1, name.length() - 1).trim();
|
||||||
|
if (trimmed.isEmpty() || trimmed.charAt(0) == '.' || trimmed.endsWith("."))
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
context.errors.invalidTable(name, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean quoted = false;
|
||||||
|
boolean dotAllowed = false;
|
||||||
|
boolean quoteAllowed = true;
|
||||||
|
boolean charAllowed = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < trimmed.length(); i++)
|
||||||
|
{
|
||||||
|
char c = trimmed.charAt(i);
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Keys.isQuote(c))
|
||||||
|
{
|
||||||
|
if (!quoteAllowed)
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
else if (quoted && trimmed.charAt(i - 1) != '\\')
|
||||||
|
{
|
||||||
|
charAllowed = false;
|
||||||
|
dotAllowed = true;
|
||||||
|
quoteAllowed = false;
|
||||||
|
}
|
||||||
|
else if (!quoted)
|
||||||
|
{
|
||||||
|
quoted = true;
|
||||||
|
quoteAllowed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (quoted)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == '.')
|
||||||
|
{
|
||||||
|
if (dotAllowed)
|
||||||
|
{
|
||||||
|
charAllowed = true;
|
||||||
|
dotAllowed = false;
|
||||||
|
quoteAllowed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.errors.emptyImplicitTable(name, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
char prev = trimmed.charAt(i - 1);
|
||||||
|
if (!Character.isWhitespace(prev) && prev != '.')
|
||||||
|
{
|
||||||
|
charAllowed = false;
|
||||||
|
dotAllowed = true;
|
||||||
|
quoteAllowed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (charAllowed && ALLOWED_CHARS.indexOf(c) > -1)
|
||||||
|
{
|
||||||
|
charAllowed = true;
|
||||||
|
dotAllowed = true;
|
||||||
|
quoteAllowed = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
context.errors.invalidTable(name, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidTableArray(String line, Context context)
|
||||||
|
{
|
||||||
|
boolean valid = line.endsWith("]]");
|
||||||
|
|
||||||
|
String trimmed = line.substring(2, line.length() - 2).trim();
|
||||||
|
if (trimmed.isEmpty() || trimmed.charAt(0) == '.' || trimmed.endsWith("."))
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
context.errors.invalidTableArray(line, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean quoted = false;
|
||||||
|
boolean dotAllowed = false;
|
||||||
|
boolean quoteAllowed = true;
|
||||||
|
boolean charAllowed = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < trimmed.length(); i++)
|
||||||
|
{
|
||||||
|
char c = trimmed.charAt(i);
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '"')
|
||||||
|
{
|
||||||
|
if (!quoteAllowed)
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
else if (quoted && trimmed.charAt(i - 1) != '\\')
|
||||||
|
{
|
||||||
|
charAllowed = false;
|
||||||
|
dotAllowed = true;
|
||||||
|
quoteAllowed = false;
|
||||||
|
}
|
||||||
|
else if (!quoted)
|
||||||
|
{
|
||||||
|
quoted = true;
|
||||||
|
quoteAllowed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (quoted)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == '.')
|
||||||
|
{
|
||||||
|
if (dotAllowed)
|
||||||
|
{
|
||||||
|
charAllowed = true;
|
||||||
|
dotAllowed = false;
|
||||||
|
quoteAllowed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.errors.emptyImplicitTable(line, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
char prev = trimmed.charAt(i - 1);
|
||||||
|
if (!Character.isWhitespace(prev) && prev != '.' && prev != '"')
|
||||||
|
{
|
||||||
|
charAllowed = false;
|
||||||
|
dotAllowed = true;
|
||||||
|
quoteAllowed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (charAllowed && ALLOWED_CHARS.indexOf(c) > -1)
|
||||||
|
{
|
||||||
|
charAllowed = true;
|
||||||
|
dotAllowed = true;
|
||||||
|
quoteAllowed = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
context.errors.invalidTableArray(line, context.line.get());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
88
proxy/src/main/java/dev/plex/toml/IdentifierConverter.java
Normal file
88
proxy/src/main/java/dev/plex/toml/IdentifierConverter.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class IdentifierConverter
|
||||||
|
{
|
||||||
|
|
||||||
|
static final IdentifierConverter IDENTIFIER_CONVERTER = new IdentifierConverter();
|
||||||
|
|
||||||
|
Identifier convert(String s, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
boolean quoted = false;
|
||||||
|
StringBuilder name = new StringBuilder();
|
||||||
|
boolean terminated = false;
|
||||||
|
boolean isKey = s.charAt(index.get()) != '[';
|
||||||
|
boolean isTableArray = !isKey && s.length() > index.get() + 1 && s.charAt(index.get() + 1) == '[';
|
||||||
|
boolean inComment = false;
|
||||||
|
|
||||||
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
if (Keys.isQuote(c) && (i == 0 || s.charAt(i - 1) != '\\'))
|
||||||
|
{
|
||||||
|
quoted = !quoted;
|
||||||
|
name.append(c);
|
||||||
|
}
|
||||||
|
else if (c == '\n')
|
||||||
|
{
|
||||||
|
index.decrementAndGet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (quoted)
|
||||||
|
{
|
||||||
|
name.append(c);
|
||||||
|
}
|
||||||
|
else if (c == '=' && isKey)
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (c == ']' && !isKey)
|
||||||
|
{
|
||||||
|
if (!isTableArray || s.length() > index.get() + 1 && s.charAt(index.get() + 1) == ']')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
name.append(']');
|
||||||
|
if (isTableArray)
|
||||||
|
{
|
||||||
|
name.append(']');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (terminated && c == '#')
|
||||||
|
{
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
else if (terminated && !Character.isWhitespace(c) && !inComment)
|
||||||
|
{
|
||||||
|
terminated = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!terminated)
|
||||||
|
{
|
||||||
|
name.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!terminated)
|
||||||
|
{
|
||||||
|
if (isKey)
|
||||||
|
{
|
||||||
|
context.errors.unterminatedKey(name.toString(), context.line.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.errors.invalidKey(name.toString(), context.line.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Identifier.INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Identifier.from(name.toString(), context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IdentifierConverter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
35
proxy/src/main/java/dev/plex/toml/IndentationPolicy.java
Normal file
35
proxy/src/main/java/dev/plex/toml/IndentationPolicy.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls how a {@link TomlWriter} indents tables and key/value pairs.
|
||||||
|
* <p>
|
||||||
|
* The default policy is to not indent.
|
||||||
|
*/
|
||||||
|
public class IndentationPolicy
|
||||||
|
{
|
||||||
|
private final int tableIndent;
|
||||||
|
private final int keyValueIndent;
|
||||||
|
private final int arrayDelimiterPadding;
|
||||||
|
|
||||||
|
IndentationPolicy(int keyIndentation, int tableIndentation, int arrayDelimiterPadding)
|
||||||
|
{
|
||||||
|
this.keyValueIndent = keyIndentation;
|
||||||
|
this.tableIndent = tableIndentation;
|
||||||
|
this.arrayDelimiterPadding = arrayDelimiterPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTableIndent()
|
||||||
|
{
|
||||||
|
return tableIndent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getKeyValueIndent()
|
||||||
|
{
|
||||||
|
return keyValueIndent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getArrayDelimiterPadding()
|
||||||
|
{
|
||||||
|
return arrayDelimiterPadding;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
class InlineTableValueReader implements dev.plex.toml.ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
|
static final InlineTableValueReader INLINE_TABLE_VALUE_READER = new InlineTableValueReader();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("{");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger sharedIndex, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int startIndex = sharedIndex.get();
|
||||||
|
boolean inKey = true;
|
||||||
|
boolean inValue = false;
|
||||||
|
boolean terminated = false;
|
||||||
|
StringBuilder currentKey = new StringBuilder();
|
||||||
|
HashMap<String, Object> results = new HashMap<String, Object>();
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
|
||||||
|
for (int i = sharedIndex.incrementAndGet(); sharedIndex.get() < s.length(); i = sharedIndex.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (inValue && !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
Object converted = dev.plex.toml.ValueReaders.VALUE_READERS.convert(s, sharedIndex, context.with(dev.plex.toml.Identifier.from(currentKey.toString(), context)));
|
||||||
|
|
||||||
|
if (converted instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
errors.add((dev.plex.toml.Results.Errors) converted);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
String currentKeyTrimmed = currentKey.toString().trim();
|
||||||
|
Object previous = results.put(currentKeyTrimmed, converted);
|
||||||
|
|
||||||
|
if (previous != null)
|
||||||
|
{
|
||||||
|
errors.duplicateKey(currentKeyTrimmed, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentKey = new StringBuilder();
|
||||||
|
inValue = false;
|
||||||
|
}
|
||||||
|
else if (c == ',')
|
||||||
|
{
|
||||||
|
inKey = true;
|
||||||
|
inValue = false;
|
||||||
|
currentKey = new StringBuilder();
|
||||||
|
}
|
||||||
|
else if (c == '=')
|
||||||
|
{
|
||||||
|
inKey = false;
|
||||||
|
inValue = true;
|
||||||
|
}
|
||||||
|
else if (c == '}')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (inKey)
|
||||||
|
{
|
||||||
|
currentKey.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!terminated)
|
||||||
|
{
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex), startLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.hasErrors())
|
||||||
|
{
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InlineTableValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
86
proxy/src/main/java/dev/plex/toml/Keys.java
Normal file
86
proxy/src/main/java/dev/plex/toml/Keys.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class Keys
|
||||||
|
{
|
||||||
|
|
||||||
|
static class Key
|
||||||
|
{
|
||||||
|
final String name;
|
||||||
|
final int index;
|
||||||
|
final String path;
|
||||||
|
|
||||||
|
Key(String name, int index, Key next)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.index = index;
|
||||||
|
if (next != null)
|
||||||
|
{
|
||||||
|
this.path = name + "." + next.path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.path = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Key[] split(String key)
|
||||||
|
{
|
||||||
|
List<Key> splitKey = new ArrayList<Key>();
|
||||||
|
StringBuilder current = new StringBuilder();
|
||||||
|
boolean quoted = false;
|
||||||
|
boolean indexable = true;
|
||||||
|
boolean inIndex = false;
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
for (int i = key.length() - 1; i > -1; i--)
|
||||||
|
{
|
||||||
|
char c = key.charAt(i);
|
||||||
|
if (c == ']' && indexable)
|
||||||
|
{
|
||||||
|
inIndex = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
indexable = false;
|
||||||
|
if (c == '[' && inIndex)
|
||||||
|
{
|
||||||
|
inIndex = false;
|
||||||
|
index = Integer.parseInt(current.toString());
|
||||||
|
current = new StringBuilder();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isQuote(c) && (i == 0 || key.charAt(i - 1) != '\\'))
|
||||||
|
{
|
||||||
|
quoted = !quoted;
|
||||||
|
indexable = false;
|
||||||
|
}
|
||||||
|
if (c != '.' || quoted)
|
||||||
|
{
|
||||||
|
current.insert(0, c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
||||||
|
indexable = true;
|
||||||
|
index = -1;
|
||||||
|
current = new StringBuilder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
||||||
|
|
||||||
|
return splitKey.toArray(new Key[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isQuote(char c)
|
||||||
|
{
|
||||||
|
return c == '"' || c == '\'';
|
||||||
|
}
|
||||||
|
|
||||||
|
private Keys()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class LiteralStringValueReader implements ValueReader
|
||||||
|
{
|
||||||
|
public static final LiteralStringValueReader LITERAL_STRING_VALUE_READER = new LiteralStringValueReader();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
int startLine = context.line.get();
|
||||||
|
boolean terminated = false;
|
||||||
|
int startIndex = index.incrementAndGet();
|
||||||
|
|
||||||
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == '\'')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!terminated)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex), startLine);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
String substring = s.substring(startIndex, index.get());
|
||||||
|
|
||||||
|
return substring;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LiteralStringValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
181
proxy/src/main/java/dev/plex/toml/MapValueWriter.java
Normal file
181
proxy/src/main/java/dev/plex/toml/MapValueWriter.java
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
class MapValueWriter implements dev.plex.toml.ValueWriter
|
||||||
|
{
|
||||||
|
static final dev.plex.toml.ValueWriter MAP_VALUE_WRITER = new MapValueWriter();
|
||||||
|
|
||||||
|
private static final Pattern REQUIRED_QUOTING_PATTERN = Pattern.compile("^.*[^A-Za-z\\d_-].*$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof Map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
File file = null;
|
||||||
|
if (context.file != null)
|
||||||
|
{
|
||||||
|
file = context.file;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<?, ?> from = (Map<?, ?>) value;
|
||||||
|
|
||||||
|
Toml toml = null;
|
||||||
|
|
||||||
|
if (file != null)
|
||||||
|
{
|
||||||
|
toml = new Toml().read(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasPrimitiveValues(from, context))
|
||||||
|
{
|
||||||
|
if (context.hasRun)
|
||||||
|
{
|
||||||
|
if (toml != null)
|
||||||
|
{
|
||||||
|
if (!toml.getValues().containsKey(context.key))
|
||||||
|
{
|
||||||
|
context.writeKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.writeKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Render primitive types and arrays of primitive first so they are
|
||||||
|
// grouped under the same table (if there is one)
|
||||||
|
for (Map.Entry<?, ?> entry : from.entrySet())
|
||||||
|
{
|
||||||
|
Object key = entry.getKey();
|
||||||
|
Object fromValue = entry.getValue();
|
||||||
|
if (fromValue == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.hasRun && toml != null)
|
||||||
|
{
|
||||||
|
if (context.key != null)
|
||||||
|
{
|
||||||
|
if (key.toString().equalsIgnoreCase(context.key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (toml.contains(context.key + "." + key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.ValueWriter valueWriter = dev.plex.toml.ValueWriters.WRITERS.findWriterFor(fromValue);
|
||||||
|
if (valueWriter.isPrimitiveType())
|
||||||
|
{
|
||||||
|
context.indent();
|
||||||
|
context.write(quoteKey(key)).write(" = ");
|
||||||
|
valueWriter.write(fromValue, context);
|
||||||
|
context.write('\n');
|
||||||
|
}
|
||||||
|
else if (valueWriter == dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER)
|
||||||
|
{
|
||||||
|
context.indent();
|
||||||
|
context.setArrayKey(key.toString());
|
||||||
|
context.write(quoteKey(key)).write(" = ");
|
||||||
|
valueWriter.write(fromValue, context);
|
||||||
|
context.write('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now render (sub)tables and arrays of tables
|
||||||
|
for (Object key : from.keySet())
|
||||||
|
{
|
||||||
|
Object fromValue = from.get(key);
|
||||||
|
if (fromValue == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.hasRun && toml != null)
|
||||||
|
{
|
||||||
|
if (context.key != null)
|
||||||
|
{
|
||||||
|
if (key.toString().equalsIgnoreCase(context.key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (toml.contains(context.key + "." + key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.ValueWriter valueWriter = dev.plex.toml.ValueWriters.WRITERS.findWriterFor(fromValue);
|
||||||
|
if (valueWriter == this || valueWriter == dev.plex.toml.ObjectValueWriter.OBJECT_VALUE_WRITER || valueWriter == dev.plex.toml.TableArrayValueWriter.TABLE_ARRAY_VALUE_WRITER)
|
||||||
|
{
|
||||||
|
WriterContext context1 = context.pushTable(quoteKey(key));
|
||||||
|
context1.parentName = key.toString();
|
||||||
|
context1.hasRun = true;
|
||||||
|
context1.file = context.file;
|
||||||
|
valueWriter.write(fromValue, context1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String quoteKey(Object key)
|
||||||
|
{
|
||||||
|
String stringKey = key.toString();
|
||||||
|
Matcher matcher = REQUIRED_QUOTING_PATTERN.matcher(stringKey);
|
||||||
|
if (matcher.matches())
|
||||||
|
{
|
||||||
|
stringKey = "\"" + stringKey + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasPrimitiveValues(Map<?, ?> values, WriterContext context)
|
||||||
|
{
|
||||||
|
for (Object key : values.keySet())
|
||||||
|
{
|
||||||
|
Object fromValue = values.get(key);
|
||||||
|
if (fromValue == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.ValueWriter valueWriter = dev.plex.toml.ValueWriters.WRITERS.findWriterFor(fromValue);
|
||||||
|
if (valueWriter.isPrimitiveType() || valueWriter == dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private MapValueWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
class MultilineLiteralStringValueReader implements ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
|
static final MultilineLiteralStringValueReader MULTILINE_LITERAL_STRING_VALUE_READER = new MultilineLiteralStringValueReader();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("'''");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int originalStartIndex = index.get();
|
||||||
|
int startIndex = index.addAndGet(3);
|
||||||
|
int endIndex = -1;
|
||||||
|
|
||||||
|
if (s.charAt(startIndex) == '\n')
|
||||||
|
{
|
||||||
|
startIndex = index.incrementAndGet();
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = startIndex; i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '\'' && s.length() > i + 2 && s.charAt(i + 1) == '\'' && s.charAt(i + 2) == '\'')
|
||||||
|
{
|
||||||
|
endIndex = i;
|
||||||
|
index.addAndGet(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex == -1)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.substring(startIndex, endIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MultilineLiteralStringValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
class MultilineStringValueReader implements ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
|
static final MultilineStringValueReader MULTILINE_STRING_VALUE_READER = new MultilineStringValueReader();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("\"\"\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int originalStartIndex = index.get();
|
||||||
|
int startIndex = index.addAndGet(3);
|
||||||
|
int endIndex = -1;
|
||||||
|
|
||||||
|
if (s.charAt(startIndex) == '\n')
|
||||||
|
{
|
||||||
|
startIndex = index.incrementAndGet();
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = startIndex; i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
else if (c == '"' && s.length() > i + 2 && s.charAt(i + 1) == '"' && s.charAt(i + 2) == '"')
|
||||||
|
{
|
||||||
|
endIndex = i;
|
||||||
|
index.addAndGet(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex == -1)
|
||||||
|
{
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s.substring(startIndex, endIndex);
|
||||||
|
s = s.replaceAll("\\\\\\s+", "");
|
||||||
|
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(s);
|
||||||
|
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceSpecialCharacters(s);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MultilineStringValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
134
proxy/src/main/java/dev/plex/toml/NumberValueReaderWriter.java
Normal file
134
proxy/src/main/java/dev/plex/toml/NumberValueReaderWriter.java
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
class NumberValueReaderWriter implements dev.plex.toml.ValueReader, dev.plex.toml.ValueWriter
|
||||||
|
{
|
||||||
|
static final NumberValueReaderWriter NUMBER_VALUE_READER_WRITER = new NumberValueReaderWriter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
char firstChar = s.charAt(0);
|
||||||
|
|
||||||
|
return firstChar == '+' || firstChar == '-' || Character.isDigit(firstChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
boolean signable = true;
|
||||||
|
boolean dottable = false;
|
||||||
|
boolean exponentable = false;
|
||||||
|
boolean terminatable = false;
|
||||||
|
boolean underscorable = false;
|
||||||
|
String type = "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
boolean notLastChar = s.length() > i + 1;
|
||||||
|
|
||||||
|
if (Character.isDigit(c))
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
signable = false;
|
||||||
|
terminatable = true;
|
||||||
|
if (type.isEmpty())
|
||||||
|
{
|
||||||
|
type = "integer";
|
||||||
|
dottable = true;
|
||||||
|
}
|
||||||
|
underscorable = notLastChar;
|
||||||
|
exponentable = !type.equals("exponent");
|
||||||
|
}
|
||||||
|
else if ((c == '+' || c == '-') && signable && notLastChar)
|
||||||
|
{
|
||||||
|
signable = false;
|
||||||
|
terminatable = false;
|
||||||
|
if (c == '-')
|
||||||
|
{
|
||||||
|
sb.append('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '.' && dottable && notLastChar)
|
||||||
|
{
|
||||||
|
sb.append('.');
|
||||||
|
type = "float";
|
||||||
|
terminatable = false;
|
||||||
|
dottable = false;
|
||||||
|
exponentable = false;
|
||||||
|
underscorable = false;
|
||||||
|
}
|
||||||
|
else if ((c == 'E' || c == 'e') && exponentable && notLastChar)
|
||||||
|
{
|
||||||
|
sb.append('E');
|
||||||
|
type = "exponent";
|
||||||
|
terminatable = false;
|
||||||
|
signable = true;
|
||||||
|
dottable = false;
|
||||||
|
exponentable = false;
|
||||||
|
underscorable = false;
|
||||||
|
}
|
||||||
|
else if (c == '_' && underscorable && notLastChar && Character.isDigit(s.charAt(i + 1)))
|
||||||
|
{
|
||||||
|
underscorable = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!terminatable)
|
||||||
|
{
|
||||||
|
type = "";
|
||||||
|
}
|
||||||
|
index.decrementAndGet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("integer"))
|
||||||
|
{
|
||||||
|
return Long.valueOf(sb.toString());
|
||||||
|
}
|
||||||
|
else if (type.equals("float"))
|
||||||
|
{
|
||||||
|
return Double.valueOf(sb.toString());
|
||||||
|
}
|
||||||
|
else if (type.equals("exponent"))
|
||||||
|
{
|
||||||
|
String[] exponentString = sb.toString().split("E");
|
||||||
|
|
||||||
|
return Double.parseDouble(exponentString[0]) * Math.pow(10, Double.parseDouble(exponentString[1]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), sb.toString(), context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof Number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, dev.plex.toml.WriterContext context)
|
||||||
|
{
|
||||||
|
context.write(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "number";
|
||||||
|
}
|
||||||
|
}
|
95
proxy/src/main/java/dev/plex/toml/ObjectValueWriter.java
Normal file
95
proxy/src/main/java/dev/plex/toml/ObjectValueWriter.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
class ObjectValueWriter implements ValueWriter
|
||||||
|
{
|
||||||
|
static final ValueWriter OBJECT_VALUE_WRITER = new ObjectValueWriter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
Map<String, Object> to = new LinkedHashMap<String, Object>();
|
||||||
|
Set<Field> fields = getFields(value.getClass());
|
||||||
|
for (Field field : fields)
|
||||||
|
{
|
||||||
|
if (field.isAnnotationPresent(SerializedName.class))
|
||||||
|
{
|
||||||
|
to.put(field.getDeclaredAnnotation(SerializedName.class).value(), getFieldValue(field, value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
to.put(field.getName(), getFieldValue(field, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MapValueWriter.MAP_VALUE_WRITER.write(to, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<Field> getFields(Class<?> cls)
|
||||||
|
{
|
||||||
|
Set<Field> fields = new LinkedHashSet<Field>(Arrays.asList(cls.getDeclaredFields()));
|
||||||
|
while (cls != Object.class)
|
||||||
|
{
|
||||||
|
fields.addAll(Arrays.asList(cls.getDeclaredFields()));
|
||||||
|
cls = cls.getSuperclass();
|
||||||
|
}
|
||||||
|
removeConstantsAndSyntheticFields(fields);
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeConstantsAndSyntheticFields(Set<Field> fields)
|
||||||
|
{
|
||||||
|
Iterator<Field> iterator = fields.iterator();
|
||||||
|
while (iterator.hasNext())
|
||||||
|
{
|
||||||
|
Field field = iterator.next();
|
||||||
|
if ((Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) || field.isSynthetic() || Modifier.isTransient(field.getModifiers()))
|
||||||
|
{
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object getFieldValue(Field field, Object o)
|
||||||
|
{
|
||||||
|
boolean isAccessible = field.isAccessible();
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object value = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
value = field.get(o);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
field.setAccessible(isAccessible);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectValueWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
class PrimitiveArrayValueWriter extends ArrayValueWriter
|
||||||
|
{
|
||||||
|
static final ValueWriter PRIMITIVE_ARRAY_VALUE_WRITER = new PrimitiveArrayValueWriter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return isArrayish(value) && isArrayOfPrimitive(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object o, WriterContext context)
|
||||||
|
{
|
||||||
|
Collection<?> values = normalize(o);
|
||||||
|
|
||||||
|
context.write('[');
|
||||||
|
context.writeArrayDelimiterPadding();
|
||||||
|
|
||||||
|
boolean first = true;
|
||||||
|
ValueWriter firstWriter = null;
|
||||||
|
|
||||||
|
for (Object value : values)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
firstWriter = ValueWriters.WRITERS.findWriterFor(value);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ValueWriter writer = ValueWriters.WRITERS.findWriterFor(value);
|
||||||
|
if (writer != firstWriter)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(
|
||||||
|
context.getContextPath() +
|
||||||
|
": cannot write a heterogeneous array; first element was of type " + firstWriter +
|
||||||
|
" but found " + writer
|
||||||
|
);
|
||||||
|
}
|
||||||
|
context.write(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueWriters.WRITERS.findWriterFor(value).write(value, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.writeArrayDelimiterPadding();
|
||||||
|
context.write(']');
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrimitiveArrayValueWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "primitive-array";
|
||||||
|
}
|
||||||
|
}
|
361
proxy/src/main/java/dev/plex/toml/Results.java
Normal file
361
proxy/src/main/java/dev/plex/toml/Results.java
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
class Results
|
||||||
|
{
|
||||||
|
|
||||||
|
static class Errors
|
||||||
|
{
|
||||||
|
|
||||||
|
private final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
void duplicateTable(String table, int line)
|
||||||
|
{
|
||||||
|
sb.append("Duplicate table definition on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": [")
|
||||||
|
.append(table)
|
||||||
|
.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tableDuplicatesKey(String table, AtomicInteger line)
|
||||||
|
{
|
||||||
|
sb.append("Key already exists for table defined on line ")
|
||||||
|
.append(line.get())
|
||||||
|
.append(": [")
|
||||||
|
.append(table)
|
||||||
|
.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyDuplicatesTable(String key, AtomicInteger line)
|
||||||
|
{
|
||||||
|
sb.append("Table already exists for key defined on line ")
|
||||||
|
.append(line.get())
|
||||||
|
.append(": ")
|
||||||
|
.append(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void emptyImplicitTable(String table, int line)
|
||||||
|
{
|
||||||
|
sb.append("Invalid table definition due to empty implicit table name: ")
|
||||||
|
.append(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invalidTable(String table, int line)
|
||||||
|
{
|
||||||
|
sb.append("Invalid table definition on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(table)
|
||||||
|
.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
void duplicateKey(String key, int line)
|
||||||
|
{
|
||||||
|
sb.append("Duplicate key");
|
||||||
|
if (line > -1)
|
||||||
|
{
|
||||||
|
sb.append(" on line ")
|
||||||
|
.append(line);
|
||||||
|
}
|
||||||
|
sb.append(": ")
|
||||||
|
.append(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invalidTextAfterIdentifier(dev.plex.toml.Identifier identifier, char text, int line)
|
||||||
|
{
|
||||||
|
sb.append("Invalid text after key ")
|
||||||
|
.append(identifier.getName())
|
||||||
|
.append(" on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(". Make sure to terminate the value or add a comment (#).");
|
||||||
|
}
|
||||||
|
|
||||||
|
void invalidKey(String key, int line)
|
||||||
|
{
|
||||||
|
sb.append("Invalid key on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invalidTableArray(String tableArray, int line)
|
||||||
|
{
|
||||||
|
sb.append("Invalid table array definition on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(tableArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invalidValue(String key, String value, int line)
|
||||||
|
{
|
||||||
|
sb.append("Invalid value on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(key)
|
||||||
|
.append(" = ")
|
||||||
|
.append(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unterminatedKey(String key, int line)
|
||||||
|
{
|
||||||
|
sb.append("Key is not followed by an equals sign on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unterminated(String key, String value, int line)
|
||||||
|
{
|
||||||
|
sb.append("Unterminated value on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(key)
|
||||||
|
.append(" = ")
|
||||||
|
.append(value.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void heterogenous(String key, int line)
|
||||||
|
{
|
||||||
|
sb.append(key)
|
||||||
|
.append(" becomes a heterogeneous array on line ")
|
||||||
|
.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasErrors()
|
||||||
|
{
|
||||||
|
return sb.length() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Errors other)
|
||||||
|
{
|
||||||
|
sb.append(other.sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Errors errors = new Errors();
|
||||||
|
private final Set<String> tables = new HashSet<String>();
|
||||||
|
private final Deque<Container> stack = new ArrayDeque<Container>();
|
||||||
|
|
||||||
|
Results()
|
||||||
|
{
|
||||||
|
stack.push(new Container.Table(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
void addValue(String key, Object value, AtomicInteger line)
|
||||||
|
{
|
||||||
|
Container currentTable = stack.peek();
|
||||||
|
|
||||||
|
if (value instanceof Map)
|
||||||
|
{
|
||||||
|
String path = getInlineTablePath(key);
|
||||||
|
if (path == null)
|
||||||
|
{
|
||||||
|
startTable(key, line);
|
||||||
|
}
|
||||||
|
else if (path.isEmpty())
|
||||||
|
{
|
||||||
|
startTables(dev.plex.toml.Identifier.from(key, null), line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startTables(dev.plex.toml.Identifier.from(path, null), line);
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> valueMap = (Map<String, Object>) value;
|
||||||
|
for (Map.Entry<String, Object> entry : valueMap.entrySet())
|
||||||
|
{
|
||||||
|
addValue(entry.getKey(), entry.getValue(), line);
|
||||||
|
}
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
else if (currentTable.accepts(key))
|
||||||
|
{
|
||||||
|
currentTable.put(key, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (currentTable.get(key) instanceof Container)
|
||||||
|
{
|
||||||
|
errors.keyDuplicatesTable(key, line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.duplicateKey(key, line != null ? line.get() : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startTableArray(dev.plex.toml.Identifier identifier, AtomicInteger line)
|
||||||
|
{
|
||||||
|
String tableName = identifier.getBareName();
|
||||||
|
while (stack.size() > 1)
|
||||||
|
{
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
||||||
|
for (int i = 0; i < tableParts.length; i++)
|
||||||
|
{
|
||||||
|
String tablePart = tableParts[i].name;
|
||||||
|
Container currentContainer = stack.peek();
|
||||||
|
|
||||||
|
if (currentContainer.get(tablePart) instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
Container.TableArray currentTableArray = (Container.TableArray) currentContainer.get(tablePart);
|
||||||
|
stack.push(currentTableArray);
|
||||||
|
|
||||||
|
if (i == tableParts.length - 1)
|
||||||
|
{
|
||||||
|
currentTableArray.put(tablePart, new Container.Table());
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.push(currentTableArray.getCurrent());
|
||||||
|
currentContainer = stack.peek();
|
||||||
|
}
|
||||||
|
else if (currentContainer.get(tablePart) instanceof Container.Table && i < tableParts.length - 1)
|
||||||
|
{
|
||||||
|
Container nextTable = (Container) currentContainer.get(tablePart);
|
||||||
|
stack.push(nextTable);
|
||||||
|
}
|
||||||
|
else if (currentContainer.accepts(tablePart))
|
||||||
|
{
|
||||||
|
Container newContainer = i == tableParts.length - 1 ? new Container.TableArray() : new Container.Table();
|
||||||
|
addValue(tablePart, newContainer, line);
|
||||||
|
stack.push(newContainer);
|
||||||
|
|
||||||
|
if (newContainer instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
stack.push(((Container.TableArray) newContainer).getCurrent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.duplicateTable(tableName, line.get());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startTables(dev.plex.toml.Identifier id, AtomicInteger line)
|
||||||
|
{
|
||||||
|
String tableName = id.getBareName();
|
||||||
|
|
||||||
|
while (stack.size() > 1)
|
||||||
|
{
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
||||||
|
for (int i = 0; i < tableParts.length; i++)
|
||||||
|
{
|
||||||
|
String tablePart = tableParts[i].name;
|
||||||
|
Container currentContainer = stack.peek();
|
||||||
|
if (currentContainer.get(tablePart) instanceof Container)
|
||||||
|
{
|
||||||
|
Container nextTable = (Container) currentContainer.get(tablePart);
|
||||||
|
if (i == tableParts.length - 1 && !nextTable.isImplicit())
|
||||||
|
{
|
||||||
|
errors.duplicateTable(tableName, line.get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stack.push(nextTable);
|
||||||
|
if (stack.peek() instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
stack.push(((Container.TableArray) stack.peek()).getCurrent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (currentContainer.accepts(tablePart))
|
||||||
|
{
|
||||||
|
startTable(tablePart, i < tableParts.length - 1, line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.tableDuplicatesKey(tablePart, line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: After this method has been called, this instance is no longer usable.
|
||||||
|
*/
|
||||||
|
Map<String, Object> consume()
|
||||||
|
{
|
||||||
|
Container values = stack.getLast();
|
||||||
|
stack.clear();
|
||||||
|
|
||||||
|
return ((Container.Table) values).consume();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container startTable(String tableName, AtomicInteger line)
|
||||||
|
{
|
||||||
|
Container newTable = new Container.Table(tableName);
|
||||||
|
addValue(tableName, newTable, line);
|
||||||
|
stack.push(newTable);
|
||||||
|
|
||||||
|
return newTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container startTable(String tableName, boolean implicit, AtomicInteger line)
|
||||||
|
{
|
||||||
|
Container newTable = new Container.Table(tableName, implicit);
|
||||||
|
addValue(tableName, newTable, line);
|
||||||
|
stack.push(newTable);
|
||||||
|
|
||||||
|
return newTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getInlineTablePath(String key)
|
||||||
|
{
|
||||||
|
Iterator<Container> descendingIterator = stack.descendingIterator();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
while (descendingIterator.hasNext())
|
||||||
|
{
|
||||||
|
Container next = descendingIterator.next();
|
||||||
|
if (next instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Container.Table table = (Container.Table) next;
|
||||||
|
|
||||||
|
if (table.name == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb.length() > 0)
|
||||||
|
{
|
||||||
|
sb.append('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(table.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb.length() > 0)
|
||||||
|
{
|
||||||
|
sb.append('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(key)
|
||||||
|
.insert(0, '[')
|
||||||
|
.append(']');
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
154
proxy/src/main/java/dev/plex/toml/StringValueReaderWriter.java
Normal file
154
proxy/src/main/java/dev/plex/toml/StringValueReaderWriter.java
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
class StringValueReaderWriter implements ValueReader, ValueWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
static final StringValueReaderWriter STRING_VALUE_READER_WRITER = new StringValueReaderWriter();
|
||||||
|
private static final Pattern UNICODE_REGEX = Pattern.compile("\\\\[uU](.{4})");
|
||||||
|
|
||||||
|
static private final String[] specialCharacterEscapes = new String[93];
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
specialCharacterEscapes['\b'] = "\\b";
|
||||||
|
specialCharacterEscapes['\t'] = "\\t";
|
||||||
|
specialCharacterEscapes['\n'] = "\\n";
|
||||||
|
specialCharacterEscapes['\f'] = "\\f";
|
||||||
|
specialCharacterEscapes['\r'] = "\\r";
|
||||||
|
specialCharacterEscapes['"'] = "\\\"";
|
||||||
|
specialCharacterEscapes['\\'] = "\\\\";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRead(String s)
|
||||||
|
{
|
||||||
|
return s.startsWith("\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
int startIndex = index.incrementAndGet();
|
||||||
|
int endIndex = -1;
|
||||||
|
|
||||||
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char ch = s.charAt(i);
|
||||||
|
if (ch == '"' && s.charAt(i - 1) != '\\')
|
||||||
|
{
|
||||||
|
endIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex == -1)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex - 1), context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
String raw = s.substring(startIndex, endIndex);
|
||||||
|
s = replaceUnicodeCharacters(raw);
|
||||||
|
s = replaceSpecialCharacters(s);
|
||||||
|
|
||||||
|
if (s == null)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), raw, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
String replaceUnicodeCharacters(String value)
|
||||||
|
{
|
||||||
|
Matcher unicodeMatcher = UNICODE_REGEX.matcher(value);
|
||||||
|
|
||||||
|
while (unicodeMatcher.find())
|
||||||
|
{
|
||||||
|
value = value.replace(unicodeMatcher.group(), new String(Character.toChars(Integer.parseInt(unicodeMatcher.group(1), 16))));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
String replaceSpecialCharacters(String s)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < s.length() - 1; i++)
|
||||||
|
{
|
||||||
|
char ch = s.charAt(i);
|
||||||
|
char next = s.charAt(i + 1);
|
||||||
|
|
||||||
|
if (ch == '\\' && next == '\\')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if (ch == '\\' && !(next == 'b' || next == 'f' || next == 'n' || next == 't' || next == 'r' || next == '"' || next == '\\'))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.replace("\\n", "\n")
|
||||||
|
.replace("\\\"", "\"")
|
||||||
|
.replace("\\t", "\t")
|
||||||
|
.replace("\\r", "\r")
|
||||||
|
.replace("\\\\", "\\")
|
||||||
|
.replace("\\/", "/")
|
||||||
|
.replace("\\b", "\b")
|
||||||
|
.replace("\\f", "\f");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof String || value instanceof Character || value instanceof URL || value instanceof URI || value instanceof Enum;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
context.write('"');
|
||||||
|
escapeUnicode(value.toString(), context);
|
||||||
|
context.write('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void escapeUnicode(String in, WriterContext context)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < in.length(); i++)
|
||||||
|
{
|
||||||
|
int codePoint = in.codePointAt(i);
|
||||||
|
if (codePoint < specialCharacterEscapes.length && specialCharacterEscapes[codePoint] != null)
|
||||||
|
{
|
||||||
|
context.write(specialCharacterEscapes[codePoint]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.write(in.charAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringValueReaderWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
}
|
38
proxy/src/main/java/dev/plex/toml/TableArrayValueWriter.java
Normal file
38
proxy/src/main/java/dev/plex/toml/TableArrayValueWriter.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||||
|
|
||||||
|
class TableArrayValueWriter extends ArrayValueWriter
|
||||||
|
{
|
||||||
|
static final ValueWriter TABLE_ARRAY_VALUE_WRITER = new TableArrayValueWriter();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return isArrayish(value) && !isArrayOfPrimitive(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object from, WriterContext context)
|
||||||
|
{
|
||||||
|
Collection<?> values = normalize(from);
|
||||||
|
|
||||||
|
WriterContext subContext = context.pushTableFromArray();
|
||||||
|
|
||||||
|
for (Object value : values)
|
||||||
|
{
|
||||||
|
WRITERS.findWriterFor(value).write(value, subContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TableArrayValueWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "table-array";
|
||||||
|
}
|
||||||
|
}
|
500
proxy/src/main/java/dev/plex/toml/Toml.java
Normal file
500
proxy/src/main/java/dev/plex/toml/Toml.java
Normal file
@ -0,0 +1,500 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Provides access to the keys and tables in a TOML data source.</p>
|
||||||
|
*
|
||||||
|
* <p>All getters can fall back to default values if they have been provided as a constructor argument.
|
||||||
|
* Getters for simple values (String, Date, etc.) will return null if no matching key exists.
|
||||||
|
* {@link #getList(String)}, {@link #getTable(String)} and {@link #getTables(String)} return empty values if there is no matching key.</p>
|
||||||
|
*
|
||||||
|
* <p>All read methods throw an {@link IllegalStateException} if the TOML is incorrect.</p>
|
||||||
|
*
|
||||||
|
* <p>Example usage:</p>
|
||||||
|
* <pre><code>
|
||||||
|
* Toml toml = new Toml().read(getTomlFile());
|
||||||
|
* String name = toml.getString("name");
|
||||||
|
* Long port = toml.getLong("server.ip"); // compound key. Is equivalent to:
|
||||||
|
* Long port2 = toml.getTable("server").getLong("ip");
|
||||||
|
* MyConfig config = toml.to(MyConfig.class);
|
||||||
|
* </code></pre>
|
||||||
|
*/
|
||||||
|
public class Toml
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final Gson DEFAULT_GSON = new Gson();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Map<String, Object> values = new HashMap<String, Object>();
|
||||||
|
private final Toml defaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Toml instance with no defaults.
|
||||||
|
*/
|
||||||
|
public Toml()
|
||||||
|
{
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param defaults fallback values used when the requested key or table is not present in the TOML source that has been read.
|
||||||
|
*/
|
||||||
|
public Toml(Toml defaults)
|
||||||
|
{
|
||||||
|
this(defaults, new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the current Toml instance with values from file.
|
||||||
|
*
|
||||||
|
* @param file The File to be read. Expected to be encoded as UTF-8.
|
||||||
|
* @return this instance
|
||||||
|
* @throws IllegalStateException If file contains invalid TOML
|
||||||
|
*/
|
||||||
|
public Toml read(File file)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return read(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the current Toml instance with values from inputStream.
|
||||||
|
*
|
||||||
|
* @param inputStream Closed after it has been read.
|
||||||
|
* @return this instance
|
||||||
|
* @throws IllegalStateException If file contains invalid TOML
|
||||||
|
*/
|
||||||
|
public Toml read(InputStream inputStream)
|
||||||
|
{
|
||||||
|
return read(new InputStreamReader(inputStream));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the current Toml instance with values from reader.
|
||||||
|
*
|
||||||
|
* @param reader Closed after it has been read.
|
||||||
|
* @return this instance
|
||||||
|
* @throws IllegalStateException If file contains invalid TOML
|
||||||
|
*/
|
||||||
|
public Toml read(Reader reader)
|
||||||
|
{
|
||||||
|
BufferedReader bufferedReader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bufferedReader = new BufferedReader(reader);
|
||||||
|
|
||||||
|
StringBuilder w = new StringBuilder();
|
||||||
|
String line = bufferedReader.readLine();
|
||||||
|
while (line != null)
|
||||||
|
{
|
||||||
|
w.append(line).append('\n');
|
||||||
|
line = bufferedReader.readLine();
|
||||||
|
}
|
||||||
|
read(w.toString());
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bufferedReader.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the current Toml instance with values from otherToml.
|
||||||
|
*
|
||||||
|
* @param otherToml
|
||||||
|
* @return this instance
|
||||||
|
*/
|
||||||
|
public Toml read(Toml otherToml)
|
||||||
|
{
|
||||||
|
this.values = otherToml.values;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the current Toml instance with values from tomlString.
|
||||||
|
*
|
||||||
|
* @param tomlString String to be read.
|
||||||
|
* @return this instance
|
||||||
|
* @throws IllegalStateException If tomlString is not valid TOML
|
||||||
|
*/
|
||||||
|
public Toml read(String tomlString) throws IllegalStateException
|
||||||
|
{
|
||||||
|
dev.plex.toml.Results results = dev.plex.toml.TomlParser.run(tomlString);
|
||||||
|
if (results.errors.hasErrors())
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(results.errors.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.values = results.consume();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key)
|
||||||
|
{
|
||||||
|
return (String) get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key, String defaultValue)
|
||||||
|
{
|
||||||
|
String val = getString(key);
|
||||||
|
return val == null ? defaultValue : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLong(String key)
|
||||||
|
{
|
||||||
|
return (Long) get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLong(String key, Long defaultValue)
|
||||||
|
{
|
||||||
|
Long val = getLong(key);
|
||||||
|
return val == null ? defaultValue : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key a TOML key
|
||||||
|
* @param <T> type of list items
|
||||||
|
* @return <code>null</code> if the key is not found
|
||||||
|
*/
|
||||||
|
public <T> List<T> getList(String key)
|
||||||
|
{
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<T> list = (List<T>) get(key);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key a TOML key
|
||||||
|
* @param defaultValue a list of default values
|
||||||
|
* @param <T> type of list items
|
||||||
|
* @return <code>null</code> is the key is not found
|
||||||
|
*/
|
||||||
|
public <T> List<T> getList(String key, List<T> defaultValue)
|
||||||
|
{
|
||||||
|
List<T> list = getList(key);
|
||||||
|
|
||||||
|
return list != null ? list : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getBoolean(String key)
|
||||||
|
{
|
||||||
|
return (Boolean) get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getBoolean(String key, Boolean defaultValue)
|
||||||
|
{
|
||||||
|
Boolean val = getBoolean(key);
|
||||||
|
return val == null ? defaultValue : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate(String key)
|
||||||
|
{
|
||||||
|
return (Date) get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate(String key, Date defaultValue)
|
||||||
|
{
|
||||||
|
Date val = getDate(key);
|
||||||
|
return val == null ? defaultValue : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getDouble(String key)
|
||||||
|
{
|
||||||
|
return (Double) get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getDouble(String key, Double defaultValue)
|
||||||
|
{
|
||||||
|
Double val = getDouble(key);
|
||||||
|
return val == null ? defaultValue : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key A table name, not including square brackets.
|
||||||
|
* @return A new Toml instance or <code>null</code> if no value is found for key.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Toml getTable(String key)
|
||||||
|
{
|
||||||
|
Map<String, Object> map = (Map<String, Object>) get(key);
|
||||||
|
|
||||||
|
return map != null ? new Toml(null, map) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key Name of array of tables, not including square brackets.
|
||||||
|
* @return A {@link List} of Toml instances or <code>null</code> if no value is found for key.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<Toml> getTables(String key)
|
||||||
|
{
|
||||||
|
List<Map<String, Object>> tableArray = (List<Map<String, Object>>) get(key);
|
||||||
|
|
||||||
|
if (tableArray == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Toml> tables = new ArrayList<Toml>();
|
||||||
|
|
||||||
|
for (Map<String, Object> table : tableArray)
|
||||||
|
{
|
||||||
|
tables.add(new Toml(null, table));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key a key name, can be compound (eg. a.b.c)
|
||||||
|
* @return true if key is present
|
||||||
|
*/
|
||||||
|
public boolean contains(String key)
|
||||||
|
{
|
||||||
|
return get(key) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key a key name, can be compound (eg. a.b.c)
|
||||||
|
* @return true if key is present and is a primitive
|
||||||
|
*/
|
||||||
|
public boolean containsPrimitive(String key)
|
||||||
|
{
|
||||||
|
Object object = get(key);
|
||||||
|
|
||||||
|
return object != null && !(object instanceof Map) && !(object instanceof List);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key a key name, can be compound (eg. a.b.c)
|
||||||
|
* @return true if key is present and is a table
|
||||||
|
*/
|
||||||
|
public boolean containsTable(String key)
|
||||||
|
{
|
||||||
|
Object object = get(key);
|
||||||
|
|
||||||
|
return object != null && (object instanceof Map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key a key name, can be compound (eg. a.b.c)
|
||||||
|
* @return true if key is present and is a table array
|
||||||
|
*/
|
||||||
|
public boolean containsTableArray(String key)
|
||||||
|
{
|
||||||
|
Object object = get(key);
|
||||||
|
|
||||||
|
return object != null && (object instanceof List);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty()
|
||||||
|
{
|
||||||
|
return values.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Populates an instance of targetClass with the values of this Toml instance.
|
||||||
|
* The target's field names must match keys or tables.
|
||||||
|
* Keys not present in targetClass will be ignored.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>Tables are recursively converted to custom classes or to {@link Map Map<String, Object>}.</p>
|
||||||
|
*
|
||||||
|
* <p>In addition to straight-forward conversion of TOML primitives, the following are also available:</p>
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>Integer -> int, long (or wrapper), {@link java.math.BigInteger}</li>
|
||||||
|
* <li>Float -> float, double (or wrapper), {@link java.math.BigDecimal}</li>
|
||||||
|
* <li>One-letter String -> char, {@link Character}</li>
|
||||||
|
* <li>String -> {@link String}, enum, {@link java.net.URI}, {@link java.net.URL}</li>
|
||||||
|
* <li>Multiline and Literal Strings -> {@link String}</li>
|
||||||
|
* <li>Array -> {@link List}, {@link Set}, array. The generic type can be anything that can be converted.</li>
|
||||||
|
* <li>Table -> Custom class, {@link Map Map<String, Object>}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param targetClass Class to deserialize TOML to.
|
||||||
|
* @param <T> type of targetClass.
|
||||||
|
* @return A new instance of targetClass.
|
||||||
|
*/
|
||||||
|
public <T> T to(Class<T> targetClass)
|
||||||
|
{
|
||||||
|
JsonElement json = DEFAULT_GSON.toJsonTree(toMap());
|
||||||
|
|
||||||
|
if (targetClass == JsonElement.class)
|
||||||
|
{
|
||||||
|
return targetClass.cast(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DEFAULT_GSON.fromJson(json, targetClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> toMap()
|
||||||
|
{
|
||||||
|
HashMap<String, Object> valuesCopy = new HashMap<String, Object>(values);
|
||||||
|
|
||||||
|
if (defaults != null)
|
||||||
|
{
|
||||||
|
for (Map.Entry<String, Object> entry : defaults.values.entrySet())
|
||||||
|
{
|
||||||
|
if (!valuesCopy.containsKey(entry.getKey()))
|
||||||
|
{
|
||||||
|
valuesCopy.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return valuesCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a {@link Set} of Map.Entry instances. Modifications to the {@link Set} are not reflected in this Toml instance. Entries are immutable, so {@link Map.Entry#setValue(Object)} throws an UnsupportedOperationException.
|
||||||
|
*/
|
||||||
|
public Set<Map.Entry<String, Object>> entrySet()
|
||||||
|
{
|
||||||
|
Set<Map.Entry<String, Object>> entries = new LinkedHashSet<Map.Entry<String, Object>>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet())
|
||||||
|
{
|
||||||
|
Class<? extends Object> entryClass = entry.getValue().getClass();
|
||||||
|
|
||||||
|
if (Map.class.isAssignableFrom(entryClass))
|
||||||
|
{
|
||||||
|
entries.add(new Entry(entry.getKey(), getTable(entry.getKey())));
|
||||||
|
}
|
||||||
|
else if (List.class.isAssignableFrom(entryClass))
|
||||||
|
{
|
||||||
|
List<?> value = (List<?>) entry.getValue();
|
||||||
|
if (!value.isEmpty() && value.get(0) instanceof Map)
|
||||||
|
{
|
||||||
|
entries.add(new Entry(entry.getKey(), getTables(entry.getKey())));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entries.add(new Entry(entry.getKey(), value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entries.add(new Entry(entry.getKey(), entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Entry implements Map.Entry<String, Object>
|
||||||
|
{
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
private final Object value;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey()
|
||||||
|
{
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object setValue(Object value)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("TOML entry values cannot be changed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Entry(String key, Object value)
|
||||||
|
{
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Object get(String key)
|
||||||
|
{
|
||||||
|
if (values.containsKey(key))
|
||||||
|
{
|
||||||
|
return values.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object current = new HashMap<>(values);
|
||||||
|
|
||||||
|
dev.plex.toml.Keys.Key[] keys = dev.plex.toml.Keys.split(key);
|
||||||
|
|
||||||
|
for (dev.plex.toml.Keys.Key k : keys)
|
||||||
|
{
|
||||||
|
if (k.index == -1 && current instanceof Map && ((Map<String, Object>) current).containsKey(k.path))
|
||||||
|
{
|
||||||
|
return ((Map<String, Object>) current).get(k.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
current = ((Map<String, Object>) current).get(k.name);
|
||||||
|
|
||||||
|
if (k.index > -1 && current != null)
|
||||||
|
{
|
||||||
|
if (k.index >= ((List<?>) current).size())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = ((List<?>) current).get(k.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current == null)
|
||||||
|
{
|
||||||
|
return defaults != null ? defaults.get(key) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Toml(Toml defaults, Map<String, Object> values)
|
||||||
|
{
|
||||||
|
this.values = values;
|
||||||
|
this.defaults = defaults;
|
||||||
|
}
|
||||||
|
}
|
88
proxy/src/main/java/dev/plex/toml/TomlParser.java
Normal file
88
proxy/src/main/java/dev/plex/toml/TomlParser.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
class TomlParser
|
||||||
|
{
|
||||||
|
|
||||||
|
static dev.plex.toml.Results run(String tomlString)
|
||||||
|
{
|
||||||
|
final dev.plex.toml.Results results = new dev.plex.toml.Results();
|
||||||
|
|
||||||
|
if (tomlString.isEmpty())
|
||||||
|
{
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicInteger index = new AtomicInteger();
|
||||||
|
boolean inComment = false;
|
||||||
|
AtomicInteger line = new AtomicInteger(1);
|
||||||
|
dev.plex.toml.Identifier identifier = null;
|
||||||
|
Object value = null;
|
||||||
|
|
||||||
|
for (int i = index.get(); i < tomlString.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = tomlString.charAt(i);
|
||||||
|
|
||||||
|
if (results.errors.hasErrors())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '#' && !inComment)
|
||||||
|
{
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
else if (!Character.isWhitespace(c) && !inComment && identifier == null)
|
||||||
|
{
|
||||||
|
dev.plex.toml.Identifier id = dev.plex.toml.IdentifierConverter.IDENTIFIER_CONVERTER.convert(tomlString, index, new dev.plex.toml.Context(null, line, results.errors));
|
||||||
|
|
||||||
|
if (id != dev.plex.toml.Identifier.INVALID)
|
||||||
|
{
|
||||||
|
if (id.isKey())
|
||||||
|
{
|
||||||
|
identifier = id;
|
||||||
|
}
|
||||||
|
else if (id.isTable())
|
||||||
|
{
|
||||||
|
results.startTables(id, line);
|
||||||
|
}
|
||||||
|
else if (id.isTableArray())
|
||||||
|
{
|
||||||
|
results.startTableArray(id, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '\n')
|
||||||
|
{
|
||||||
|
inComment = false;
|
||||||
|
identifier = null;
|
||||||
|
value = null;
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
else if (!inComment && identifier != null && identifier.isKey() && value == null && !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
value = ValueReaders.VALUE_READERS.convert(tomlString, index, new dev.plex.toml.Context(identifier, line, results.errors));
|
||||||
|
|
||||||
|
if (value instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
results.errors.add((dev.plex.toml.Results.Errors) value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
results.addValue(identifier.getName(), value, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value != null && !inComment && !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
results.errors.invalidTextAfterIdentifier(identifier, c, line.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TomlParser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
186
proxy/src/main/java/dev/plex/toml/TomlWriter.java
Normal file
186
proxy/src/main/java/dev/plex/toml/TomlWriter.java
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Converts Objects to TOML</p>
|
||||||
|
*
|
||||||
|
* <p>An input Object can comprise arbitrarily nested combinations of Java primitive types,
|
||||||
|
* other {@link Object}s, {@link Map}s, {@link List}s, and Arrays. {@link Object}s and {@link Map}s
|
||||||
|
* are output to TOML tables, and {@link List}s and Array to TOML arrays.</p>
|
||||||
|
*
|
||||||
|
* <p>Example usage:</p>
|
||||||
|
* <pre><code>
|
||||||
|
* class AClass {
|
||||||
|
* int anInt = 1;
|
||||||
|
* int[] anArray = { 2, 3 };
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* String tomlString = new TomlWriter().write(new AClass());
|
||||||
|
* </code></pre>
|
||||||
|
*/
|
||||||
|
public class TomlWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
public static class Builder
|
||||||
|
{
|
||||||
|
private int keyIndentation;
|
||||||
|
private int tableIndentation;
|
||||||
|
private int arrayDelimiterPadding = 0;
|
||||||
|
private TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
||||||
|
private boolean showFractionalSeconds = false;
|
||||||
|
|
||||||
|
public Builder indentValuesBy(int spaces)
|
||||||
|
{
|
||||||
|
this.keyIndentation = spaces;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder indentTablesBy(int spaces)
|
||||||
|
{
|
||||||
|
this.tableIndentation = spaces;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder timeZone(TimeZone timeZone)
|
||||||
|
{
|
||||||
|
this.timeZone = timeZone;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param spaces number of spaces to put between opening square bracket and first item and between closing square bracket and last item
|
||||||
|
* @return this TomlWriter.Builder instance
|
||||||
|
*/
|
||||||
|
public Builder padArrayDelimitersBy(int spaces)
|
||||||
|
{
|
||||||
|
this.arrayDelimiterPadding = spaces;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TomlWriter build()
|
||||||
|
{
|
||||||
|
return new TomlWriter(keyIndentation, tableIndentation, arrayDelimiterPadding, timeZone, showFractionalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder showFractionalSeconds()
|
||||||
|
{
|
||||||
|
this.showFractionalSeconds = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final IndentationPolicy indentationPolicy;
|
||||||
|
private final dev.plex.toml.DatePolicy datePolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a TomlWriter instance.
|
||||||
|
*/
|
||||||
|
public TomlWriter()
|
||||||
|
{
|
||||||
|
this(0, 0, 0, TimeZone.getTimeZone("UTC"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TomlWriter(int keyIndentation, int tableIndentation, int arrayDelimiterPadding, TimeZone timeZone, boolean showFractionalSeconds)
|
||||||
|
{
|
||||||
|
this.indentationPolicy = new IndentationPolicy(keyIndentation, tableIndentation, arrayDelimiterPadding);
|
||||||
|
this.datePolicy = new dev.plex.toml.DatePolicy(timeZone, showFractionalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an Object into TOML String.
|
||||||
|
*
|
||||||
|
* @param from the object to be written
|
||||||
|
* @return a string containing the TOML representation of the given Object
|
||||||
|
*/
|
||||||
|
public String write(Object from)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringWriter output = new StringWriter();
|
||||||
|
write(from, output, null);
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an Object in TOML to a {@link File}. Output is encoded as UTF-8.
|
||||||
|
*
|
||||||
|
* @param from the object to be written
|
||||||
|
* @param target the File to which the TOML will be written
|
||||||
|
* @throws IOException if any file operations fail
|
||||||
|
*/
|
||||||
|
public void write(Object from, File target) throws IOException
|
||||||
|
{
|
||||||
|
OutputStream outputStream = new FileOutputStream(target, true);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
write(from, outputStream, target);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an Object in TOML to a {@link OutputStream}. Output is encoded as UTF-8.
|
||||||
|
*
|
||||||
|
* @param from the object to be written
|
||||||
|
* @param target the OutputStream to which the TOML will be written. The stream is NOT closed after being written to.
|
||||||
|
* @throws IOException if target.write() fails
|
||||||
|
*/
|
||||||
|
public void write(Object from, OutputStream target, @Nullable File file) throws IOException
|
||||||
|
{
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(target, StandardCharsets.UTF_8);
|
||||||
|
write(from, writer, file);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an Object in TOML to a {@link Writer}. You MUST ensure that the {@link Writer}s's encoding is set to UTF-8 for the TOML to be valid.
|
||||||
|
*
|
||||||
|
* @param from the object to be written. Can be a Map or a custom type. Must not be null.
|
||||||
|
* @param target the Writer to which TOML will be written. The Writer is not closed.
|
||||||
|
* @throws IOException if target.write() fails
|
||||||
|
* @throws IllegalArgumentException if from is of an invalid type
|
||||||
|
*/
|
||||||
|
public void write(Object from, Writer target, @Nullable File file) throws IOException
|
||||||
|
{
|
||||||
|
dev.plex.toml.ValueWriter valueWriter = WRITERS.findWriterFor(from);
|
||||||
|
if (valueWriter == MapValueWriter.MAP_VALUE_WRITER || valueWriter == dev.plex.toml.ObjectValueWriter.OBJECT_VALUE_WRITER)
|
||||||
|
{
|
||||||
|
WriterContext context = new WriterContext(indentationPolicy, datePolicy, target);
|
||||||
|
if (file != null && file.exists())
|
||||||
|
{
|
||||||
|
context.file = file;
|
||||||
|
}
|
||||||
|
valueWriter.write(from, context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("An object of class " + from.getClass().getSimpleName() + " cannot produce valid TOML. Please pass in a Map or a custom type.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
proxy/src/main/java/dev/plex/toml/ValueReader.java
Normal file
21
proxy/src/main/java/dev/plex/toml/ValueReader.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
interface ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param s must already have been trimmed
|
||||||
|
*/
|
||||||
|
boolean canRead(String s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Partial validation. Stops after type terminator, rather than at EOI.
|
||||||
|
*
|
||||||
|
* @param s must already have been validated by {@link #canRead(String)}
|
||||||
|
* @param index where to start in s
|
||||||
|
* @return a value or a {@link dev.plex.toml.Results.Errors}
|
||||||
|
*/
|
||||||
|
Object read(String s, AtomicInteger index, dev.plex.toml.Context context);
|
||||||
|
}
|
40
proxy/src/main/java/dev/plex/toml/ValueReaders.java
Normal file
40
proxy/src/main/java/dev/plex/toml/ValueReaders.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import static dev.plex.toml.ArrayValueReader.ARRAY_VALUE_READER;
|
||||||
|
import static dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER;
|
||||||
|
import static dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
||||||
|
import static dev.plex.toml.LiteralStringValueReader.LITERAL_STRING_VALUE_READER;
|
||||||
|
import static dev.plex.toml.MultilineLiteralStringValueReader.MULTILINE_LITERAL_STRING_VALUE_READER;
|
||||||
|
import static dev.plex.toml.MultilineStringValueReader.MULTILINE_STRING_VALUE_READER;
|
||||||
|
import static dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER;
|
||||||
|
|
||||||
|
class ValueReaders
|
||||||
|
{
|
||||||
|
|
||||||
|
static final ValueReaders VALUE_READERS = new ValueReaders();
|
||||||
|
|
||||||
|
Object convert(String value, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
String substring = value.substring(index.get());
|
||||||
|
for (dev.plex.toml.ValueReader valueParser : READERS)
|
||||||
|
{
|
||||||
|
if (valueParser.canRead(substring))
|
||||||
|
{
|
||||||
|
return valueParser.read(value, index, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), substring, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ValueReaders()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final dev.plex.toml.ValueReader[] READERS = {
|
||||||
|
MULTILINE_STRING_VALUE_READER, MULTILINE_LITERAL_STRING_VALUE_READER, LITERAL_STRING_VALUE_READER, STRING_VALUE_READER_WRITER, DATE_VALUE_READER_WRITER, NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER, BOOLEAN_VALUE_READER_WRITER, ARRAY_VALUE_READER, InlineTableValueReader.INLINE_TABLE_VALUE_READER
|
||||||
|
};
|
||||||
|
}
|
10
proxy/src/main/java/dev/plex/toml/ValueWriter.java
Normal file
10
proxy/src/main/java/dev/plex/toml/ValueWriter.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
interface ValueWriter
|
||||||
|
{
|
||||||
|
boolean canWrite(Object value);
|
||||||
|
|
||||||
|
void write(Object value, WriterContext context);
|
||||||
|
|
||||||
|
boolean isPrimitiveType();
|
||||||
|
}
|
35
proxy/src/main/java/dev/plex/toml/ValueWriters.java
Normal file
35
proxy/src/main/java/dev/plex/toml/ValueWriters.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
class ValueWriters
|
||||||
|
{
|
||||||
|
|
||||||
|
static final ValueWriters WRITERS = new ValueWriters();
|
||||||
|
|
||||||
|
ValueWriter findWriterFor(Object value)
|
||||||
|
{
|
||||||
|
for (ValueWriter valueWriter : VALUE_WRITERS)
|
||||||
|
{
|
||||||
|
if (valueWriter.canWrite(value))
|
||||||
|
{
|
||||||
|
return valueWriter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ObjectValueWriter.OBJECT_VALUE_WRITER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ValueWriters()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static dev.plex.toml.DateValueReaderWriter getPlatformSpecificDateConverter()
|
||||||
|
{
|
||||||
|
String specificationVersion = Runtime.class.getPackage().getSpecificationVersion();
|
||||||
|
return specificationVersion != null && specificationVersion.startsWith("1.6") ? dev.plex.toml.DateValueReaderWriter.DATE_PARSER_JDK_6 : dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ValueWriter[] VALUE_WRITERS = {
|
||||||
|
StringValueReaderWriter.STRING_VALUE_READER_WRITER, NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER, dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER, getPlatformSpecificDateConverter(),
|
||||||
|
MapValueWriter.MAP_VALUE_WRITER, dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER, TableArrayValueWriter.TABLE_ARRAY_VALUE_WRITER
|
||||||
|
};
|
||||||
|
}
|
185
proxy/src/main/java/dev/plex/toml/WriterContext.java
Normal file
185
proxy/src/main/java/dev/plex/toml/WriterContext.java
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
class WriterContext
|
||||||
|
{
|
||||||
|
private String arrayKey = null;
|
||||||
|
private boolean isArrayOfTable = false;
|
||||||
|
private boolean empty = true;
|
||||||
|
public final String key;
|
||||||
|
private final String currentTableIndent;
|
||||||
|
private final String currentFieldIndent;
|
||||||
|
private final Writer output;
|
||||||
|
private final dev.plex.toml.IndentationPolicy indentationPolicy;
|
||||||
|
private final dev.plex.toml.DatePolicy datePolicy;
|
||||||
|
|
||||||
|
public File file;
|
||||||
|
public String parentName;
|
||||||
|
public boolean hasRun = false;
|
||||||
|
|
||||||
|
WriterContext(dev.plex.toml.IndentationPolicy indentationPolicy, dev.plex.toml.DatePolicy datePolicy, Writer output)
|
||||||
|
{
|
||||||
|
this("", "", output, indentationPolicy, datePolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
WriterContext pushTable(String newKey)
|
||||||
|
{
|
||||||
|
String newIndent = "";
|
||||||
|
if (!key.isEmpty())
|
||||||
|
{
|
||||||
|
newIndent = growIndent(indentationPolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fullKey = key.isEmpty() ? newKey : key + "." + newKey;
|
||||||
|
|
||||||
|
WriterContext subContext = new WriterContext(fullKey, newIndent, output, indentationPolicy, datePolicy);
|
||||||
|
if (!empty)
|
||||||
|
{
|
||||||
|
subContext.empty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return subContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
WriterContext pushTableFromArray()
|
||||||
|
{
|
||||||
|
WriterContext subContext = new WriterContext(key, currentTableIndent, output, indentationPolicy, datePolicy);
|
||||||
|
if (!empty)
|
||||||
|
{
|
||||||
|
subContext.empty = false;
|
||||||
|
}
|
||||||
|
subContext.setIsArrayOfTable(true);
|
||||||
|
|
||||||
|
return subContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
WriterContext write(String s)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
output.write(s);
|
||||||
|
if (empty && !s.isEmpty())
|
||||||
|
{
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(char[] chars)
|
||||||
|
{
|
||||||
|
for (char c : chars)
|
||||||
|
{
|
||||||
|
write(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WriterContext write(char c)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
output.write(c);
|
||||||
|
empty = false;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeKey()
|
||||||
|
{
|
||||||
|
if (key.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty)
|
||||||
|
{
|
||||||
|
write('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
write(currentTableIndent);
|
||||||
|
|
||||||
|
if (isArrayOfTable)
|
||||||
|
{
|
||||||
|
write("[[").write(key).write("]]\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
write('[').write(key).write("]\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeArrayDelimiterPadding()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < indentationPolicy.getArrayDelimiterPadding(); i++)
|
||||||
|
{
|
||||||
|
write(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void indent()
|
||||||
|
{
|
||||||
|
if (!key.isEmpty())
|
||||||
|
{
|
||||||
|
write(currentFieldIndent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.DatePolicy getDatePolicy()
|
||||||
|
{
|
||||||
|
return datePolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
WriterContext setIsArrayOfTable(boolean isArrayOfTable)
|
||||||
|
{
|
||||||
|
this.isArrayOfTable = isArrayOfTable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WriterContext setArrayKey(String arrayKey)
|
||||||
|
{
|
||||||
|
this.arrayKey = arrayKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getContextPath()
|
||||||
|
{
|
||||||
|
return key.isEmpty() ? arrayKey : key + "." + arrayKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String growIndent(dev.plex.toml.IndentationPolicy indentationPolicy)
|
||||||
|
{
|
||||||
|
return currentTableIndent + fillStringWithSpaces(indentationPolicy.getTableIndent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String fillStringWithSpaces(int count)
|
||||||
|
{
|
||||||
|
char[] chars = new char[count];
|
||||||
|
Arrays.fill(chars, ' ');
|
||||||
|
|
||||||
|
return new String(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WriterContext(String key, String tableIndent, Writer output, dev.plex.toml.IndentationPolicy indentationPolicy, dev.plex.toml.DatePolicy datePolicy)
|
||||||
|
{
|
||||||
|
this.key = key;
|
||||||
|
this.output = output;
|
||||||
|
this.indentationPolicy = indentationPolicy;
|
||||||
|
this.currentTableIndent = tableIndent;
|
||||||
|
this.datePolicy = datePolicy;
|
||||||
|
this.currentFieldIndent = tableIndent + fillStringWithSpaces(this.indentationPolicy.getKeyValueIndent());
|
||||||
|
}
|
||||||
|
}
|
66
proxy/src/main/java/dev/plex/util/PlexLog.java
Normal file
66
proxy/src/main/java/dev/plex/util/PlexLog.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.settings.ServerSettings;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
public class PlexLog
|
||||||
|
{
|
||||||
|
public static void log(String message, Object... strings)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strings.length; i++)
|
||||||
|
{
|
||||||
|
if (message.contains("{" + i + "}"))
|
||||||
|
{
|
||||||
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<yellow>[Plex] <gray>" + message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(Component component)
|
||||||
|
{
|
||||||
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(Component.text("[Plex] ").color(NamedTextColor.YELLOW).append(component).colorIfAbsent(NamedTextColor.GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String message, Object... strings)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strings.length; i++)
|
||||||
|
{
|
||||||
|
if (message.contains("{" + i + "}"))
|
||||||
|
{
|
||||||
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<red>[Plex Error] <gold>" + message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String message, Object... strings)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strings.length; i++)
|
||||||
|
{
|
||||||
|
if (message.contains("{" + i + "}"))
|
||||||
|
{
|
||||||
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(String message, Object... strings)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strings.length; i++)
|
||||||
|
{
|
||||||
|
if (message.contains("{" + i + "}"))
|
||||||
|
{
|
||||||
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Plex.get().getConfig().as(ServerSettings.class).getServer().isDebug())
|
||||||
|
{
|
||||||
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<dark_purple>[Plex Debug] <gold>" + message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
proxy/src/main/java/dev/plex/util/RandomUtil.java
Normal file
33
proxy/src/main/java/dev/plex/util/RandomUtil.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
public class RandomUtil
|
||||||
|
{
|
||||||
|
public static NamedTextColor getRandomColor()
|
||||||
|
{
|
||||||
|
NamedTextColor[] colors = NamedTextColor.NAMES.values().stream().filter(namedTextColor -> namedTextColor != NamedTextColor.BLACK && namedTextColor != NamedTextColor.DARK_BLUE).toArray(NamedTextColor[]::new);
|
||||||
|
return colors[randomNum(colors.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean randomBoolean()
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int randomNum()
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int randomNum(int limit)
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextInt(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int randomNum(int start, int limit)
|
||||||
|
{
|
||||||
|
return ThreadLocalRandom.current().nextInt(start, limit);
|
||||||
|
}
|
||||||
|
}
|
57
proxy/src/main/java/dev/plex/util/ReflectionsUtil.java
Normal file
57
proxy/src/main/java/dev/plex/util/ReflectionsUtil.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.reflect.ClassPath;
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ReflectionsUtil
|
||||||
|
{
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public static Set<Class<?>> getClassesFrom(String packageName)
|
||||||
|
{
|
||||||
|
Set<Class<?>> classes = new HashSet<>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ClassPath path = ClassPath.from(Plex.class.getClassLoader());
|
||||||
|
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
|
||||||
|
infoSet.forEach(info ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class<?> clazz = Class.forName(info.getName());
|
||||||
|
classes.add(clazz);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
PlexLog.error("Something went wrong while fetching classes from " + packageName);
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSet(classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> Set<Class<? extends T>> getClassesBySubType(String packageName, Class<T> subType)
|
||||||
|
{
|
||||||
|
Set<Class<?>> loadedClasses = getClassesFrom(packageName);
|
||||||
|
Set<Class<? extends T>> classes = new HashSet<>();
|
||||||
|
loadedClasses.forEach(clazz ->
|
||||||
|
{
|
||||||
|
if (clazz.getSuperclass() == subType || Arrays.asList(clazz.getInterfaces()).contains(subType))
|
||||||
|
{
|
||||||
|
classes.add((Class<? extends T>) clazz);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.unmodifiableSet(classes);
|
||||||
|
}
|
||||||
|
}
|
31
proxy/src/main/resources/config.toml
Normal file
31
proxy/src/main/resources/config.toml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#############################
|
||||||
|
# #
|
||||||
|
# Plex Velocity #
|
||||||
|
# v1.1 #
|
||||||
|
# #
|
||||||
|
#############################
|
||||||
|
|
||||||
|
[server]
|
||||||
|
name = "Plexus"
|
||||||
|
|
||||||
|
# Placeholders
|
||||||
|
# %mcversion% - The Velocity Version (i.e. 3.1.2-SNAPSHOT)
|
||||||
|
# %servername% - The name provided above
|
||||||
|
# %randomgradient% - Creates a random gradient every ping of two random colors for the whole string
|
||||||
|
# Supports MiniMessage strings, no legacy & and §
|
||||||
|
motd = ["%randomgradient%%servername% - %mcversion%", "Another motd"]
|
||||||
|
colorizeMotd = false
|
||||||
|
|
||||||
|
# Enables debug messages
|
||||||
|
debug = false
|
||||||
|
|
||||||
|
# Due to game code only supporting legacy color codes for
|
||||||
|
# player samples and not components, you may only use § or & here
|
||||||
|
# for colors.
|
||||||
|
sample = ["example", "example"]
|
||||||
|
|
||||||
|
# Adds this amount to the current player count
|
||||||
|
add-player-count = 0
|
||||||
|
|
||||||
|
# The max player count will always display as +1 more than the player count
|
||||||
|
plus-one-max-count = true
|
140
server/build.gradle
Normal file
140
server/build.gradle
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
plugins {
|
||||||
|
id "net.minecrell.plugin-yml.bukkit" version "0.6.1-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
library "org.projectlombok:lombok:1.18.24"
|
||||||
|
annotationProcessor "org.projectlombok:lombok:1.18.24"
|
||||||
|
library "org.json:json:20220320"
|
||||||
|
library "commons-io:commons-io:2.11.0"
|
||||||
|
library "dev.morphia.morphia:morphia-core:2.2.6"
|
||||||
|
library "redis.clients:jedis:4.2.2"
|
||||||
|
library "org.mariadb.jdbc:mariadb-java-client:3.0.4"
|
||||||
|
library "com.zaxxer:HikariCP:5.0.1"
|
||||||
|
library "org.apache.httpcomponents:httpclient:4.5.13"
|
||||||
|
library "org.apache.commons:commons-lang3:3.12.0"
|
||||||
|
library "org.apache.maven.resolver:maven-resolver-api:1.8.0"
|
||||||
|
library "org.apache.maven.resolver:maven-resolver-impl:1.8.0"
|
||||||
|
library "org.apache.maven.resolver:maven-resolver-connector-basic:1.8.0"
|
||||||
|
library "org.apache.maven.resolver:maven-resolver-transport-http:1.8.0"
|
||||||
|
library "org.apache.maven:maven-resolver-provider:3.8.5"
|
||||||
|
library "org.eclipse.jetty:jetty-server:11.0.9"
|
||||||
|
library "org.eclipse.jetty:jetty-servlet:11.0.9"
|
||||||
|
library "org.eclipse.jetty:jetty-proxy:11.0.9"
|
||||||
|
library "com.google.code.gson:gson:2.9.0"
|
||||||
|
compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT"
|
||||||
|
compileOnly("com.github.MilkBowl:VaultAPI:1.7") {
|
||||||
|
exclude group: "org.bukkit", module: "bukkit"
|
||||||
|
}
|
||||||
|
implementation "org.bstats:bstats-base:3.0.0"
|
||||||
|
implementation "org.bstats:bstats-bukkit:3.0.0"
|
||||||
|
implementation project(":api")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = rootProject.group
|
||||||
|
version = rootProject.version
|
||||||
|
description = "Plex-Server"
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveBaseName.set("Plex")
|
||||||
|
archiveClassifier.set("")
|
||||||
|
relocate "org.bstats", "dev.plex"
|
||||||
|
}
|
||||||
|
|
||||||
|
bukkit {
|
||||||
|
name = "Plex"
|
||||||
|
version = project.version
|
||||||
|
description = "Plex provides a new experience for freedom servers."
|
||||||
|
main = "dev.plex.Plex"
|
||||||
|
website = "https://plex.us.org"
|
||||||
|
authors = ["Telesphoreo", "taahanis", "supernt"]
|
||||||
|
softDepend = ["Vault"]
|
||||||
|
apiVersion = "1.18"
|
||||||
|
}
|
||||||
|
|
||||||
|
String getGitHash() {
|
||||||
|
def stdout = new ByteArrayOutputStream()
|
||||||
|
try {
|
||||||
|
exec {
|
||||||
|
commandLine "git", "rev-parse", "--short", "HEAD"
|
||||||
|
standardOutput = stdout
|
||||||
|
ignoreExitValue = true
|
||||||
|
}
|
||||||
|
} catch (GradleException e) {
|
||||||
|
logger.error("Couldn't determine Git head because Git is not installed. " + e.getMessage())
|
||||||
|
}
|
||||||
|
return stdout.size() > 0 ? stdout.toString().trim() : "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
String getBuildNumber() {
|
||||||
|
def stdout = new ByteArrayOutputStream()
|
||||||
|
try {
|
||||||
|
exec {
|
||||||
|
commandLine "git", "rev-list", "HEAD", "--count"
|
||||||
|
standardOutput = stdout
|
||||||
|
ignoreExitValue = true
|
||||||
|
}
|
||||||
|
} catch (GradleException e) {
|
||||||
|
logger.error("Couldn't determine build number because Git is not installed. " + e.getMessage())
|
||||||
|
}
|
||||||
|
return stdout.size() ? stdout.toString().trim() + " (local)" : "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
static def getDate() {
|
||||||
|
return new Date().format("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z")
|
||||||
|
}
|
||||||
|
|
||||||
|
task buildProperties {
|
||||||
|
ant.propertyfile(file: "$project.projectDir/src/main/resources/build.properties") {
|
||||||
|
entry(key: "buildAuthor", default: System.getenv("JENKINS_URL") != null ? "jenkins" : "unknown")
|
||||||
|
entry(key: "buildNumber", value: System.getenv("JENKINS_URL") != null ? System.getenv("BUILD_NUMBER") + " (Jenkins)" : getBuildNumber())
|
||||||
|
entry(key: "buildDate", value: getDate())
|
||||||
|
entry(key: "buildHead", value: getGitHash())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
finalizedBy(buildProperties)
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
finalizedBy(rootProject.tasks.copyJars)
|
||||||
|
}
|
||||||
|
|
||||||
|
javadoc {
|
||||||
|
options.memberLevel = JavadocMemberLevel.PRIVATE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
maven(MavenPublication) {
|
||||||
|
pom.withXml {
|
||||||
|
def dependenciesNode = asNode().appendNode("dependencies")
|
||||||
|
configurations.getByName("library").getAllDependencies().each { dependency ->
|
||||||
|
dependenciesNode.appendNode("dependency").with {
|
||||||
|
it.appendNode("groupId", dependency.group)
|
||||||
|
it.appendNode("artifactId", dependency.name)
|
||||||
|
it.appendNode("version", dependency.version)
|
||||||
|
it.appendNode("scope", "provided")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configurations.getByName("implementation").getAllDependencies().each { dependency ->
|
||||||
|
dependenciesNode.appendNode("dependency").with {
|
||||||
|
it.appendNode("groupId", dependency.group)
|
||||||
|
it.appendNode("artifactId", dependency.name)
|
||||||
|
it.appendNode("version", dependency.version)
|
||||||
|
it.appendNode("scope", "runtime")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
artifacts = [shadowJar]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,17 +2,19 @@ package dev.plex;
|
|||||||
|
|
||||||
import dev.plex.admin.Admin;
|
import dev.plex.admin.Admin;
|
||||||
import dev.plex.admin.AdminList;
|
import dev.plex.admin.AdminList;
|
||||||
|
import dev.plex.api.PlexApi;
|
||||||
|
import dev.plex.api.PlexApiProvider;
|
||||||
|
import dev.plex.api.plugin.PlexPlugin;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.cache.player.MongoPlayerData;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.cache.player.PlayerCache;
|
|
||||||
import dev.plex.cache.player.SQLPlayerData;
|
|
||||||
import dev.plex.cache.sql.SQLNotes;
|
|
||||||
import dev.plex.cache.sql.SQLPunishment;
|
|
||||||
import dev.plex.command.blocker.CommandBlockerManager;
|
|
||||||
import dev.plex.config.Config;
|
import dev.plex.config.Config;
|
||||||
import dev.plex.handlers.CommandHandler;
|
import dev.plex.handlers.CommandHandler;
|
||||||
import dev.plex.handlers.ListenerHandler;
|
import dev.plex.handlers.ListenerHandler;
|
||||||
|
import dev.plex.hook.VaultHook;
|
||||||
|
import dev.plex.listener.impl.ChatListener;
|
||||||
import dev.plex.module.ModuleManager;
|
import dev.plex.module.ModuleManager;
|
||||||
|
import dev.plex.permission.handler.NativePermissionHandler;
|
||||||
|
import dev.plex.permission.handler.VaultPermissionHandler;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.PunishmentManager;
|
import dev.plex.punishment.PunishmentManager;
|
||||||
import dev.plex.rank.RankManager;
|
import dev.plex.rank.RankManager;
|
||||||
@ -21,55 +23,66 @@ import dev.plex.storage.MongoConnection;
|
|||||||
import dev.plex.storage.RedisConnection;
|
import dev.plex.storage.RedisConnection;
|
||||||
import dev.plex.storage.SQLConnection;
|
import dev.plex.storage.SQLConnection;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
|
import dev.plex.storage.permission.SQLPermissions;
|
||||||
|
import dev.plex.storage.player.MongoPlayerData;
|
||||||
|
import dev.plex.storage.player.SQLPlayerData;
|
||||||
|
import dev.plex.storage.punishment.SQLNotes;
|
||||||
|
import dev.plex.storage.punishment.SQLPunishment;
|
||||||
|
import dev.plex.util.BuildInfo;
|
||||||
|
import dev.plex.util.BungeeUtil;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.UpdateChecker;
|
import dev.plex.util.UpdateChecker;
|
||||||
import dev.plex.world.CustomWorld;
|
import dev.plex.world.CustomWorld;
|
||||||
|
import java.io.File;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class Plex extends JavaPlugin
|
public class Plex extends PlexPlugin implements PlexApiProvider
|
||||||
{
|
{
|
||||||
public static final BuildProperties build = new BuildProperties();
|
|
||||||
private static Plex plugin;
|
private static Plex plugin;
|
||||||
|
|
||||||
public Config config;
|
public Config config;
|
||||||
public Config messages;
|
public Config messages;
|
||||||
public Config indefBans;
|
public Config indefBans;
|
||||||
public Config blockedCommands;
|
public Config commands;
|
||||||
|
public Config toggles;
|
||||||
|
|
||||||
|
private PlexProvider provider;
|
||||||
|
|
||||||
public File modulesFolder;
|
public File modulesFolder;
|
||||||
private StorageType storageType = StorageType.SQLITE;
|
private StorageType storageType = StorageType.SQLITE;
|
||||||
|
|
||||||
|
public static final BuildInfo build = new BuildInfo();
|
||||||
|
|
||||||
private SQLConnection sqlConnection;
|
private SQLConnection sqlConnection;
|
||||||
private MongoConnection mongoConnection;
|
private MongoConnection mongoConnection;
|
||||||
private RedisConnection redisConnection;
|
private RedisConnection redisConnection;
|
||||||
|
|
||||||
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
private MongoPlayerData mongoPlayerData;
|
private MongoPlayerData mongoPlayerData;
|
||||||
private SQLPlayerData sqlPlayerData;
|
private SQLPlayerData sqlPlayerData;
|
||||||
|
|
||||||
private SQLPunishment sqlPunishment;
|
private SQLPunishment sqlPunishment;
|
||||||
private SQLNotes sqlNotes;
|
private SQLNotes sqlNotes;
|
||||||
|
private SQLPermissions sqlPermissions;
|
||||||
|
|
||||||
private ModuleManager moduleManager;
|
private ModuleManager moduleManager;
|
||||||
private RankManager rankManager;
|
private RankManager rankManager;
|
||||||
private ServiceManager serviceManager;
|
private ServiceManager serviceManager;
|
||||||
private PunishmentManager punishmentManager;
|
private PunishmentManager punishmentManager;
|
||||||
private CommandBlockerManager commandBlockerManager;
|
|
||||||
|
|
||||||
private AdminList adminList;
|
private AdminList adminList;
|
||||||
private UpdateChecker updateChecker;
|
private UpdateChecker updateChecker;
|
||||||
private String system;
|
private String system;
|
||||||
|
|
||||||
|
|
||||||
public static Plex get()
|
public static Plex get()
|
||||||
{
|
{
|
||||||
return plugin;
|
return plugin;
|
||||||
@ -78,11 +91,13 @@ public class Plex extends JavaPlugin
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad()
|
public void onLoad()
|
||||||
{
|
{
|
||||||
|
super.onLoad();
|
||||||
plugin = this;
|
plugin = this;
|
||||||
config = new Config(this, "config.yml");
|
config = new Config(this, "config.yml");
|
||||||
messages = new Config(this, "messages.yml");
|
messages = new Config(this, "messages.yml");
|
||||||
indefBans = new Config(this, "indefbans.yml");
|
indefBans = new Config(this, "indefbans.yml");
|
||||||
blockedCommands = new Config(this, "commands.yml");
|
commands = new Config(this, "commands.yml");
|
||||||
|
toggles = new Config(this, "toggles.yml");
|
||||||
build.load(this);
|
build.load(this);
|
||||||
|
|
||||||
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
||||||
@ -94,6 +109,9 @@ public class Plex extends JavaPlugin
|
|||||||
moduleManager = new ModuleManager();
|
moduleManager = new ModuleManager();
|
||||||
moduleManager.loadAllModules();
|
moduleManager.loadAllModules();
|
||||||
moduleManager.loadModules();
|
moduleManager.loadModules();
|
||||||
|
|
||||||
|
this.setChatHandler(new ChatListener.ChatHandlerImpl());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,15 +119,17 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
config.load();
|
config.load();
|
||||||
messages.load();
|
messages.load();
|
||||||
// Don't add default entries to indefinite ban file
|
toggles.load();
|
||||||
|
|
||||||
|
// Don't add default entries to these files
|
||||||
indefBans.load(false);
|
indefBans.load(false);
|
||||||
blockedCommands.load();
|
commands.load(false);
|
||||||
|
|
||||||
sqlConnection = new SQLConnection();
|
sqlConnection = new SQLConnection();
|
||||||
mongoConnection = new MongoConnection();
|
mongoConnection = new MongoConnection();
|
||||||
redisConnection = new RedisConnection();
|
redisConnection = new RedisConnection();
|
||||||
|
|
||||||
moduleManager.enableModules();
|
playerCache = new PlayerCache();
|
||||||
|
|
||||||
system = config.getString("system");
|
system = config.getString("system");
|
||||||
|
|
||||||
@ -118,12 +138,30 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
PlexUtils.testConnections();
|
PlexUtils.testConnections();
|
||||||
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean permissions = false;
|
||||||
|
if (getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||||
|
{
|
||||||
|
VaultPermissionHandler handler = new VaultPermissionHandler();
|
||||||
|
if (VaultHook.getPermission() != null)
|
||||||
|
{
|
||||||
|
this.setPermissionHandler(handler);
|
||||||
|
permissions = true;
|
||||||
|
PlexLog.debug("Enabling Vault support for permissions with a permission plugin: " + VaultHook.getPermission().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!permissions)
|
||||||
|
{
|
||||||
|
this.setPermissionHandler(new NativePermissionHandler());
|
||||||
|
}
|
||||||
|
|
||||||
updateChecker = new UpdateChecker();
|
updateChecker = new UpdateChecker();
|
||||||
PlexLog.log("Update checking enabled");
|
PlexLog.log("Update checking enabled");
|
||||||
|
|
||||||
@ -135,7 +173,8 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
redisConnection.getJedis();
|
redisConnection.getJedis();
|
||||||
PlexLog.log("Connected to Redis!");
|
PlexLog.log("Connected to Redis!");
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
||||||
}
|
}
|
||||||
@ -143,11 +182,13 @@ public class Plex extends JavaPlugin
|
|||||||
if (storageType == StorageType.MONGODB)
|
if (storageType == StorageType.MONGODB)
|
||||||
{
|
{
|
||||||
mongoPlayerData = new MongoPlayerData();
|
mongoPlayerData = new MongoPlayerData();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
sqlPlayerData = new SQLPlayerData();
|
sqlPlayerData = new SQLPlayerData();
|
||||||
sqlPunishment = new SQLPunishment();
|
sqlPunishment = new SQLPunishment();
|
||||||
sqlNotes = new SQLNotes();
|
sqlNotes = new SQLNotes();
|
||||||
|
sqlPermissions = new SQLPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
new ListenerHandler();
|
new ListenerHandler();
|
||||||
@ -163,9 +204,6 @@ public class Plex extends JavaPlugin
|
|||||||
punishmentManager.mergeIndefiniteBans();
|
punishmentManager.mergeIndefiniteBans();
|
||||||
PlexLog.log("Punishment System initialized");
|
PlexLog.log("Punishment System initialized");
|
||||||
|
|
||||||
commandBlockerManager = new CommandBlockerManager();
|
|
||||||
PlexLog.log("Command Blocker initialized");
|
|
||||||
|
|
||||||
generateWorlds();
|
generateWorlds();
|
||||||
|
|
||||||
serviceManager = new ServiceManager();
|
serviceManager = new ServiceManager();
|
||||||
@ -174,6 +212,18 @@ public class Plex extends JavaPlugin
|
|||||||
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
|
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
|
||||||
|
|
||||||
reloadPlayers();
|
reloadPlayers();
|
||||||
|
PlexLog.debug("Registered Bukkit -> BungeeCord Plugin Messaging Channel");
|
||||||
|
PlexLog.debug("Velocity Support? " + BungeeUtil.isVelocity());
|
||||||
|
PlexLog.debug("BungeeCord Support? " + BungeeUtil.isBungeeCord());
|
||||||
|
if (BungeeUtil.isBungeeCord() && BungeeUtil.isVelocity())
|
||||||
|
{
|
||||||
|
PlexLog.warn("It seems you have both velocity and bungeecord configuration options enabled! When running Velocity, you do NOT need to enable bungeecord.");
|
||||||
|
}
|
||||||
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
|
|
||||||
|
|
||||||
|
provider = new PlexProvider();
|
||||||
|
moduleManager.enableModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -181,7 +231,7 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
Bukkit.getOnlinePlayers().forEach(player ->
|
Bukkit.getOnlinePlayers().forEach(player ->
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
PlexPlayer plexPlayer = playerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
||||||
|
|
||||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
@ -191,7 +241,8 @@ public class Plex extends JavaPlugin
|
|||||||
if (mongoPlayerData != null) //back to mongo checking
|
if (mongoPlayerData != null) //back to mongo checking
|
||||||
{
|
{
|
||||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
mongoPlayerData.update(plexPlayer); //update the player's document
|
||||||
} else if (sqlPlayerData != null) //sql checking
|
}
|
||||||
|
else if (sqlPlayerData != null) //sql checking
|
||||||
{
|
{
|
||||||
sqlPlayerData.update(plexPlayer);
|
sqlPlayerData.update(plexPlayer);
|
||||||
}
|
}
|
||||||
@ -202,6 +253,8 @@ public class Plex extends JavaPlugin
|
|||||||
redisConnection.getJedis().close();
|
redisConnection.getJedis().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
|
||||||
|
|
||||||
moduleManager.disableModules();
|
moduleManager.disableModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +273,7 @@ public class Plex extends JavaPlugin
|
|||||||
Bukkit.getOnlinePlayers().forEach(player ->
|
Bukkit.getOnlinePlayers().forEach(player ->
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
playerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
Admin admin = new Admin(plexPlayer.getUuid());
|
Admin admin = new Admin(plexPlayer.getUuid());
|
||||||
@ -231,33 +284,9 @@ public class Plex extends JavaPlugin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BuildProperties
|
@Override
|
||||||
|
public PlexApi getApi()
|
||||||
{
|
{
|
||||||
public String number;
|
return provider;
|
||||||
public String author;
|
|
||||||
public String date;
|
|
||||||
public String head;
|
|
||||||
|
|
||||||
public void load(Plex plugin)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final Properties props;
|
|
||||||
|
|
||||||
try (InputStream in = plugin.getResource("build.properties"))
|
|
||||||
{
|
|
||||||
props = new Properties();
|
|
||||||
props.load(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
number = props.getProperty("buildNumber", "unknown");
|
|
||||||
author = props.getProperty("buildAuthor", "unknown");
|
|
||||||
date = props.getProperty("buildDate", "unknown");
|
|
||||||
head = props.getProperty("buildHead", "unknown");
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
PlexLog.error("Could not load build properties! Did you compile with NetBeans/Maven?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
6
server/src/main/java/dev/plex/PlexBase.java
Normal file
6
server/src/main/java/dev/plex/PlexBase.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package dev.plex;
|
||||||
|
|
||||||
|
public interface PlexBase
|
||||||
|
{
|
||||||
|
Plex plugin = Plex.get();
|
||||||
|
}
|
14
server/src/main/java/dev/plex/PlexProvider.java
Normal file
14
server/src/main/java/dev/plex/PlexProvider.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package dev.plex;
|
||||||
|
|
||||||
|
import dev.plex.api.IPlayerCache;
|
||||||
|
import dev.plex.api.PlexApi;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
|
||||||
|
public class PlexProvider implements PlexApi
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public IPlayerCache<PlexPlayer> getPlayerCache()
|
||||||
|
{
|
||||||
|
return Plex.get().getPlayerCache();
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ import java.util.stream.Collectors;
|
|||||||
* @see Admin
|
* @see Admin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AdminList extends PlexBase
|
public class AdminList implements PlexBase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Key / Value storage, where the key is the unique ID of the admin
|
* Key / Value storage, where the key is the unique ID of the admin
|
||||||
@ -54,7 +54,7 @@ public class AdminList extends PlexBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gathers every admin's username (cached and in the database)
|
* Gathers every admins username (cached and in the database)
|
||||||
*
|
*
|
||||||
* @return An array list of the names of every admin
|
* @return An array list of the names of every admin
|
||||||
*/
|
*/
|
@ -1,11 +1,10 @@
|
|||||||
package dev.plex.cache;
|
package dev.plex.cache;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.player.PlayerCache;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent cache class
|
* Parent cache class
|
||||||
@ -30,6 +29,18 @@ public class DataUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasPlayedBefore(String username)
|
||||||
|
{
|
||||||
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
|
{
|
||||||
|
return Plex.get().getMongoPlayerData().exists(username);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Plex.get().getSqlPlayerData().exists(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a player from cache or from the database
|
* Gets a player from cache or from the database
|
||||||
*
|
*
|
||||||
@ -39,9 +50,14 @@ public class DataUtils
|
|||||||
*/
|
*/
|
||||||
public static PlexPlayer getPlayer(UUID uuid)
|
public static PlexPlayer getPlayer(UUID uuid)
|
||||||
{
|
{
|
||||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
return getPlayer(uuid, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlexPlayer getPlayer(UUID uuid, boolean loadExtraData)
|
||||||
|
{
|
||||||
|
if (Plex.get().getPlayerCache().getPlexPlayerMap().containsKey(uuid))
|
||||||
{
|
{
|
||||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
@ -50,19 +66,30 @@ public class DataUtils
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Plex.get().getSqlPlayerData().getByUUID(uuid);
|
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlexPlayer getPlayer(String username)
|
public static PlexPlayer getPlayer(String username)
|
||||||
{
|
{
|
||||||
|
return getPlayer(username, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlexPlayer getPlayer(String username, boolean loadExtraData)
|
||||||
|
{
|
||||||
|
Optional<PlexPlayer> plexPlayer = Plex.get().getPlayerCache().getPlexPlayerMap().values().stream().filter(player -> player.getName().equalsIgnoreCase(username)).findFirst();
|
||||||
|
if (plexPlayer.isPresent())
|
||||||
|
{
|
||||||
|
return plexPlayer.get();
|
||||||
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
{
|
{
|
||||||
return Plex.get().getMongoPlayerData().getByName(username);
|
return Plex.get().getMongoPlayerData().getByName(username);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Plex.get().getSqlPlayerData().getByName(username);
|
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +102,7 @@ public class DataUtils
|
|||||||
*/
|
*/
|
||||||
public static PlexPlayer getPlayerByIP(String ip)
|
public static PlexPlayer getPlayerByIP(String ip)
|
||||||
{
|
{
|
||||||
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
|
PlexPlayer player = Plex.get().getPlayerCache().getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
return player;
|
return player;
|
@ -1,6 +1,7 @@
|
|||||||
package dev.plex.cache.player;
|
package dev.plex.cache;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import dev.plex.api.IPlayerCache;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -9,7 +10,7 @@ import java.util.UUID;
|
|||||||
* Cache storage
|
* Cache storage
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class PlayerCache
|
public class PlayerCache implements IPlayerCache<PlexPlayer>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A key/value pair where the key is the unique ID of the Plex Player
|
* A key/value pair where the key is the unique ID of the Plex Player
|
||||||
@ -19,13 +20,13 @@ public class PlayerCache
|
|||||||
/**
|
/**
|
||||||
* A key/value pair where the key is the unique ID of the Punished Player
|
* A key/value pair where the key is the unique ID of the Punished Player
|
||||||
*/
|
*/
|
||||||
// private static final Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
|
// private static final Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
|
||||||
|
|
||||||
// public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
|
// public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
|
||||||
// {
|
// {
|
||||||
// return punishedPlayerMap;
|
// return punishedPlayerMap;
|
||||||
// }
|
// }
|
||||||
public static Map<UUID, PlexPlayer> getPlexPlayerMap()
|
public Map<UUID, PlexPlayer> getPlexPlayerMap()
|
||||||
{
|
{
|
||||||
return plexPlayerMap;
|
return plexPlayerMap;
|
||||||
}
|
}
|
||||||
@ -39,7 +40,7 @@ public class PlayerCache
|
|||||||
return getPunishedPlayerMap().get(uuid);
|
return getPunishedPlayerMap().get(uuid);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
public static PlexPlayer getPlexPlayer(UUID uuid)
|
public PlexPlayer getPlexPlayer(UUID uuid)
|
||||||
{
|
{
|
||||||
return getPlexPlayerMap().get(uuid);
|
return getPlexPlayerMap().get(uuid);
|
||||||
}
|
}
|
@ -2,31 +2,36 @@ package dev.plex.command;
|
|||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.cache.player.PlayerCache;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.*;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
|
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||||
|
import dev.plex.command.exception.ConsoleOnlyException;
|
||||||
|
import dev.plex.command.exception.PlayerNotBannedException;
|
||||||
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Superclass for all commands
|
* Superclass for all commands
|
||||||
*/
|
*/
|
||||||
@ -60,7 +65,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
/**
|
/**
|
||||||
* Creates an instance of the command
|
* Creates an instance of the command
|
||||||
*/
|
*/
|
||||||
public PlexCommand()
|
public PlexCommand(boolean register)
|
||||||
{
|
{
|
||||||
super("");
|
super("");
|
||||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||||
@ -77,7 +82,15 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
this.level = perms.level();
|
this.level = perms.level();
|
||||||
this.commandSource = perms.source();
|
this.commandSource = perms.source();
|
||||||
|
|
||||||
getMap().register("plex", this);
|
if (register)
|
||||||
|
{
|
||||||
|
getMap().register("plex", this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlexCommand()
|
||||||
|
{
|
||||||
|
this(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,7 +130,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
|
|
||||||
if (sender instanceof Player player)
|
if (sender instanceof Player player)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
@ -125,7 +138,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
{
|
{
|
||||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||||
return true;
|
return true;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||||
{
|
{
|
||||||
@ -133,14 +147,52 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (!player.hasPermission(perms.permission()))
|
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(player, perms.permission()))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
||||||
|
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
|
||||||
|
{
|
||||||
|
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||||
|
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
|
{
|
||||||
|
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||||
|
{
|
||||||
|
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
|
{
|
||||||
|
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
|
||||||
|
{
|
||||||
|
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
||||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
||||||
@ -154,9 +206,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
{
|
{
|
||||||
send(sender, component);
|
send(sender, component);
|
||||||
}
|
}
|
||||||
} catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
|
}
|
||||||
|
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException |
|
||||||
|
ConsoleMustDefinePlayerException | PlayerNotBannedException | NumberFormatException ex)
|
||||||
{
|
{
|
||||||
send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage()));
|
send(sender, PlexUtils.mmDeserialize(ex.getMessage()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -178,7 +232,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (params.aliases().split(",").length < 1)
|
}
|
||||||
|
else if (params.aliases().split(",").length < 1)
|
||||||
{
|
{
|
||||||
return getName().equalsIgnoreCase(label);
|
return getName().equalsIgnoreCase(label);
|
||||||
}
|
}
|
||||||
@ -234,6 +289,28 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
{
|
{
|
||||||
return checkRank((Player) sender, rank, permission);
|
return checkRank((Player) sender, rank, permission);
|
||||||
}
|
}
|
||||||
|
if (!sender.getName().equalsIgnoreCase("console"))
|
||||||
|
{
|
||||||
|
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
|
if (!plexPlayer.getRankFromString().isAtLeast(rank))
|
||||||
|
{
|
||||||
|
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||||
|
}
|
||||||
|
if (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
||||||
|
{
|
||||||
|
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
|
{
|
||||||
|
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
|
||||||
|
{
|
||||||
|
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,9 +340,10 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
||||||
}
|
}
|
||||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (!player.hasPermission(permission))
|
if (!perms.permission().isEmpty() && !plugin.getPermissionHandler().hasPermission(player, permission))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||||
}
|
}
|
||||||
@ -283,9 +361,10 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
return player.hasPermission(permission);
|
return !perms.permission().isEmpty() && plugin.getPermissionHandler().hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -323,9 +402,10 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
||||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
return player.hasPermission(permission);
|
return !perms.permission().isEmpty() && plugin.getPermissionHandler().hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -437,6 +517,18 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return PlexUtils.messageComponent(s, objects);
|
return PlexUtils.messageComponent(s, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a message entry from the "messages.yml" to a Component
|
||||||
|
*
|
||||||
|
* @param s The message entry
|
||||||
|
* @param objects Any objects to replace in order
|
||||||
|
* @return A Kyori Component
|
||||||
|
*/
|
||||||
|
protected Component messageComponent(String s, Component... objects)
|
||||||
|
{
|
||||||
|
return PlexUtils.messageComponent(s, objects);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a message entry from the "messages.yml" to a String
|
* Converts a message entry from the "messages.yml" to a String
|
||||||
*
|
*
|
||||||
@ -473,6 +565,16 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
|
|
||||||
protected Player getNonNullPlayer(String name)
|
protected Player getNonNullPlayer(String name)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UUID uuid = UUID.fromString(name);
|
||||||
|
return Bukkit.getPlayer(uuid);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ignored)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Player player = Bukkit.getPlayer(name);
|
Player player = Bukkit.getPlayer(name);
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
@ -484,7 +586,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
protected PlexPlayer getOnlinePlexPlayer(String name)
|
protected PlexPlayer getOnlinePlexPlayer(String name)
|
||||||
{
|
{
|
||||||
Player player = getNonNullPlayer(name);
|
Player player = getNonNullPlayer(name);
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId());
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(player.getUniqueId());
|
||||||
if (plexPlayer == null)
|
if (plexPlayer == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
@ -536,7 +638,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
*/
|
*/
|
||||||
protected Component mmString(String s)
|
protected Component mmString(String s)
|
||||||
{
|
{
|
||||||
return MiniMessage.miniMessage().deserialize(s);
|
return PlexUtils.mmDeserialize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rank getLevel()
|
public Rank getLevel()
|
@ -0,0 +1,16 @@
|
|||||||
|
package dev.plex.command.blocking;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BlockedCommand
|
||||||
|
{
|
||||||
|
private Component message;
|
||||||
|
private String requiredLevel;
|
||||||
|
private String regex;
|
||||||
|
private String command;
|
||||||
|
private List<String> commandAliases = Lists.newArrayList();
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.AdminAddEvent;
|
||||||
|
import dev.plex.api.event.AdminRemoveEvent;
|
||||||
|
import dev.plex.api.event.AdminSetRankEvent;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
@ -9,16 +12,11 @@ import dev.plex.command.annotation.System;
|
|||||||
import dev.plex.command.exception.ConsoleOnlyException;
|
import dev.plex.command.exception.ConsoleOnlyException;
|
||||||
import dev.plex.command.exception.PlayerNotFoundException;
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.AdminAddEvent;
|
|
||||||
import dev.plex.event.AdminRemoveEvent;
|
|
||||||
import dev.plex.event.AdminSetRankEvent;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexLog;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -54,18 +52,18 @@ public class AdminCMD extends PlexCommand
|
|||||||
throw new ConsoleOnlyException();
|
throw new ConsoleOnlyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
/*UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||||
|
|
||||||
if (targetUUID != null)
|
if (targetUUID != null)
|
||||||
{
|
{
|
||||||
PlexLog.debug("Admin Adding UUID: " + targetUUID);
|
PlexLog.debug("Admin Adding UUID: " + targetUUID);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||||
|
|
||||||
if (isAdmin(plexPlayer))
|
if (isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
@ -87,13 +85,13 @@ public class AdminCMD extends PlexCommand
|
|||||||
throw new ConsoleOnlyException();
|
throw new ConsoleOnlyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||||
|
|
||||||
if (!isAdmin(plexPlayer))
|
if (!isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
@ -116,9 +114,9 @@ public class AdminCMD extends PlexCommand
|
|||||||
throw new ConsoleOnlyException();
|
throw new ConsoleOnlyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (!DataUtils.hasPlayedBefore(args[1]))
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
@ -135,7 +133,7 @@ public class AdminCMD extends PlexCommand
|
|||||||
return messageComponent("rankMustBeHigherThanAdmin");
|
return messageComponent("rankMustBeHigherThanAdmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||||
|
|
||||||
if (!isAdmin(plexPlayer))
|
if (!isAdmin(plexPlayer))
|
||||||
{
|
{
|
@ -1,6 +1,5 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import dev.plex.cache.player.PlayerCache;
|
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
@ -38,7 +37,7 @@ public class AdminChatCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
||||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
|
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
|
||||||
{
|
{
|
||||||
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
||||||
@ -46,7 +45,7 @@ public class AdminChatCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (player.hasPermission("plex.adminchat"))
|
if (plugin.getPermissionHandler().hasPermission(player, "plex.adminchat"))
|
||||||
{
|
{
|
||||||
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "adventure", aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
|
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
|
||||||
public class AdventureCMD extends PlexCommand
|
public class AdventureCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
@ -12,9 +12,13 @@ import dev.plex.player.PlexPlayer;
|
|||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.BungeeUtil;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.time.LocalDateTime;
|
import dev.plex.util.TimeUtils;
|
||||||
|
import dev.plex.util.WebUtils;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -38,7 +42,7 @@ public class BanCMD extends PlexCommand
|
|||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
UUID targetUUID = WebUtils.getFromName(args[0]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||||
{
|
{
|
||||||
@ -47,15 +51,18 @@ public class BanCMD extends PlexCommand
|
|||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||||
Player player = Bukkit.getPlayer(targetUUID);
|
Player player = Bukkit.getPlayer(targetUUID);
|
||||||
|
|
||||||
if (isAdmin(plexPlayer))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
if (!isConsole(sender))
|
if (isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
assert playerSender != null;
|
if (!isConsole(sender))
|
||||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
|
||||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
|
||||||
{
|
{
|
||||||
return messageComponent("higherRankThanYou");
|
assert playerSender != null;
|
||||||
|
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||||
|
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||||
|
{
|
||||||
|
return messageComponent("higherRankThanYou");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +87,7 @@ public class BanCMD extends PlexCommand
|
|||||||
punishment.setReason("No reason provided.");
|
punishment.setReason("No reason provided.");
|
||||||
}
|
}
|
||||||
punishment.setPunishedUsername(plexPlayer.getName());
|
punishment.setPunishedUsername(plexPlayer.getName());
|
||||||
LocalDateTime date = LocalDateTime.now();
|
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||||
punishment.setEndDate(date.plusDays(1));
|
punishment.setEndDate(date.plusDays(1));
|
||||||
punishment.setCustomTime(false);
|
punishment.setCustomTime(false);
|
||||||
punishment.setActive(!isAdmin(plexPlayer));
|
punishment.setActive(!isAdmin(plexPlayer));
|
||||||
@ -94,7 +101,7 @@ public class BanCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
player.kick(Punishment.generateBanMessage(punishment));
|
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid());
|
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid());
|
@ -7,7 +7,6 @@ import dev.plex.listener.impl.BlockListener;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -30,7 +29,8 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list"))
|
if (args[0].equalsIgnoreCase("list"))
|
||||||
{
|
{
|
||||||
send(sender, "The following have block modification abilities restricted:");
|
send(sender, messageComponent("listOfPlayersBlocked"));
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (String player : bl.blockedPlayers.stream().toList())
|
for (String player : bl.blockedPlayers.stream().toList())
|
||||||
{
|
{
|
||||||
@ -45,7 +45,7 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("purge"))
|
else if (args[0].equalsIgnoreCase("purge"))
|
||||||
{
|
{
|
||||||
PlexUtils.broadcast(componentFromString(sender.getName() + " - Unblocking block modification abilities for all players").color(NamedTextColor.AQUA));
|
PlexUtils.broadcast(messageComponent("unblockingEdits", sender.getName(), "all players"));
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (String player : bl.blockedPlayers.stream().toList())
|
for (String player : bl.blockedPlayers.stream().toList())
|
||||||
{
|
{
|
||||||
@ -55,11 +55,11 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messageComponent("unblockedEditsSize", count);
|
return messageComponent("blockeditSize", "Unblocked", count);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("all"))
|
else if (args[0].equalsIgnoreCase("all"))
|
||||||
{
|
{
|
||||||
PlexUtils.broadcast(componentFromString(sender.getName() + " - Blocking block modification abilities for all non-admins").color(NamedTextColor.RED));
|
PlexUtils.broadcast(messageComponent("blockingEdits", sender.getName(), "all non-admins"));
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (final Player player : Bukkit.getOnlinePlayers())
|
for (final Player player : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageComponent("blockedEditsSize", count);
|
return messageComponent("blockeditSize", "Blocked", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player player = getNonNullPlayer(args[0]);
|
final Player player = getNonNullPlayer(args[0]);
|
||||||
@ -81,16 +81,16 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
send(sender, messageComponent("higherRankThanYou"));
|
send(sender, messageComponent("higherRankThanYou"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PlexUtils.broadcast(messageComponent("blockingEditFor", sender.getName(), player.getName()));
|
PlexUtils.broadcast(messageComponent("blockingEdits", sender.getName(), player.getName()));
|
||||||
bl.blockedPlayers.add(player.getName());
|
bl.blockedPlayers.add(player.getName());
|
||||||
send(player, messageComponent("yourEditsHaveBeenBlocked"));
|
send(player, messageComponent("editsModified", "blocked"));
|
||||||
send(sender, messageComponent("editsBlocked", player.getName()));
|
send(sender, messageComponent("editsBlocked", player.getName()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PlexUtils.broadcast(messageComponent("unblockingEditFor", sender.getName(), player.getName()));
|
PlexUtils.broadcast(messageComponent("unblockingEdits", sender.getName(), player.getName()));
|
||||||
bl.blockedPlayers.remove(player.getName());
|
bl.blockedPlayers.remove(player.getName());
|
||||||
send(player, messageComponent("yourEditsHaveBeenUnblocked"));
|
send(player, messageComponent("editsModified", "unblocked"));
|
||||||
send(sender, messageComponent("editsUnblocked", player.getName()));
|
send(sender, messageComponent("editsUnblocked", player.getName()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
@ -7,9 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
@ -0,0 +1,31 @@
|
|||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.command.PlexCommand;
|
||||||
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||||
|
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||||
|
public class ConsoleSayCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "creative", aliases = "gmc", description = "Set your own or another player's gamemode to creative mode")
|
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
|
||||||
public class CreativeCMD extends PlexCommand
|
public class CreativeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user