mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 16:56:40 +00:00
Compare commits
169 Commits
Author | SHA1 | Date | |
---|---|---|---|
ecbd9c02da | |||
77dc95ae29 | |||
91a1b1cfff | |||
0c6091f06a | |||
ffbad7928a | |||
7caa89539d | |||
ceb9a83eda | |||
a62bdef5b4 | |||
37649f1fdc | |||
ea512487ac | |||
41b0076f8f | |||
00b6473e4d | |||
77be23faf0 | |||
e39f882ea7 | |||
344d890877 | |||
2c8c6353c1 | |||
8fa05e3838 | |||
158ce52320 | |||
1cc431621b | |||
b9c873beb3 | |||
6e1fa15a6c | |||
c216bdc5a4 | |||
ed638679b2 | |||
76952e33b8 | |||
f3f7daaafb | |||
dbbaf4ab70 | |||
1a10fdd481 | |||
7565bb6fcf | |||
22199be335 | |||
2e077c40d2 | |||
517b829420 | |||
7fa26f9a64 | |||
09846f1d33 | |||
ed70a0ec8b | |||
16e29b80a7 | |||
829bb88959 | |||
d6b44863aa | |||
f806470fd5 | |||
3611148b4c | |||
262af44193 | |||
a014a38e2f | |||
d896179f47 | |||
9dac0e799e | |||
5c27fb00e7 | |||
679d8bcbc0 | |||
46de6dba84 | |||
d2649508b3 | |||
dd8e22b676 | |||
b26e489e83 | |||
5f64e02cae | |||
4a14f94158 | |||
6763e12d81 | |||
1d0fb85fa1 | |||
665a2f4e72 | |||
9c67911c1b | |||
f1ebbc3664 | |||
4aa3ae7c50 | |||
08e2f31eae | |||
a1c009909d | |||
7d2c44975d | |||
b2faec70a9 | |||
a0cca2aea5 | |||
337334d403 | |||
2e8fe8767e | |||
dbdf720a9e | |||
5a9d6dd60d | |||
84a9535123 | |||
41aff575d0 | |||
65b8188b37 | |||
c8a35c8e0e | |||
13acf7ba9d | |||
5fe48cfd7f | |||
abf2aca0f2 | |||
dc4ac39fe4 | |||
1ae8e779b1 | |||
658f4a4b05 | |||
7ccfb2ad27 | |||
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 |
40
.github/workflows/codeql-analysis.yml
vendored
40
.github/workflows/codeql-analysis.yml
vendored
@ -1,14 +1,3 @@
|
|||||||
# 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"
|
name: "CodeQL"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -18,7 +7,7 @@ on:
|
|||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '29 4 * * *'
|
- cron: '30 4 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
@ -33,45 +22,26 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: [ 'java' ]
|
language: [ 'java' ]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
java: [ 17 ]
|
||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK ${{ matrix.java }}
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: 17
|
java-version: ${{ matrix.java }}
|
||||||
cache: gradle
|
cache: gradle
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
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
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
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
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v2
|
||||||
|
32
.github/workflows/gradle.yml
vendored
32
.github/workflows/gradle.yml
vendored
@ -1,18 +1,26 @@
|
|||||||
name: Gradle
|
# Adapted from Paper's build script
|
||||||
|
name: Build
|
||||||
on: [ push ]
|
on: [ push, pull_request ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
# Only run on PRs if the source branch is on someone else's repo
|
||||||
|
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
java: [ 17 ]
|
||||||
|
fail-fast: true
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set up JDK 17
|
- name: JDK ${{ matrix.java }}
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
java-version: ${{ matrix.java }}
|
||||||
java-version: 17
|
cache: 'gradle'
|
||||||
cache: gradle
|
distribution: 'temurin'
|
||||||
- name: Build with Gradle
|
- name: Build
|
||||||
run: chmod a+x gradlew && ./gradlew build --no-daemon
|
run: |
|
||||||
|
git config --global user.email "no-reply@github.com"
|
||||||
|
git config --global user.name "Github Actions"
|
||||||
|
./gradlew build --stacktrace
|
||||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
*.iml
|
*.iml
|
||||||
/target/
|
/target/
|
||||||
src/main/resources/build.properties
|
server/src/main/resources/build.properties
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
@ -13,4 +13,8 @@ Thumbs.db
|
|||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
/build/
|
/build/
|
||||||
|
/*/build/
|
||||||
/.gradle/
|
/.gradle/
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
20
.idea/codeStyles/Plexus_Code_Style.xml
generated
Normal file
20
.idea/codeStyles/Plexus_Code_Style.xml
generated
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Plexus Code Style" version="173">
|
||||||
|
<codeStyleSettings language="JAVA">
|
||||||
|
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||||
|
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
|
||||||
|
<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="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>
|
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>
|
@ -1,23 +1,37 @@
|
|||||||
For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when contributing however.
|
For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when
|
||||||
|
contributing.
|
||||||
|
|
||||||
## Steps
|
## Steps
|
||||||
1. Make an isuse and get feedback. It's important to know if your idea will be accepted before writing any code.
|
|
||||||
|
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 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 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.
|
- If it is an enhancement, describe your proposed changes. Ensure you are extremely specific.
|
||||||
2. Fork Plex
|
|
||||||
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`.
|
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.
|
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
|
|
||||||
5. Push your changes to your new branch and make a PR based off of that branch.
|
- 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 the Plexus Code Style (which is almost the same as Allman) 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
|
## Requirements for a PR
|
||||||
|
|
||||||
- The issue must be marked as approved
|
- The issue must be marked as approved
|
||||||
- It must only address each specific issue. Don't make one PR for multiple issues.
|
- 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.
|
- Your PR must compile and work. If it does not compile or work, your PR will most likely be rejected.
|
||||||
|
|
||||||
## Code requirements
|
## Code requirements
|
||||||
- Most importantly, your code must be efficient. Your pull request may be rejected if your code is deemed inefficient or sloppy.
|
|
||||||
|
- 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 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.
|
- 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.
|
- Your code must be consistent with Plex's codebase. If a function already exists, use it.
|
||||||
|
16
Jenkinsfile
vendored
16
Jenkinsfile
vendored
@ -8,24 +8,12 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage("publish") {
|
|
||||||
when {
|
|
||||||
branch "master"
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
withCredentials([usernamePassword(credentialsId: '85b7099f-2e65-461e-b2ce-124edec41ed6', passwordVariable: 'plexPassword', usernameVariable: 'plexUser')]) {
|
|
||||||
withGradle {
|
|
||||||
sh "./gradlew publish --no-daemon"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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: "server/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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Plex [](https://ci.plex.us.org/job/Plex/job/master/)
|
# Plex [](https://ci.plex.us.org/job/Plex/job/master/) [](https://github.com/plexusorg/Plex/blob/master/LICENSE.md) [](https://discord.plex.us.org)
|
||||||
|
|
||||||
Plex is a new freedom plugin. It is an alternative to TotalFreedomMod. It has many of the features that make a freedom
|
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
|
server unique, but also many features that TotalFreedomMod doesn’t have. For example, there is full support for using a
|
||||||
|
152
build.gradle
152
build.gradle
@ -1,14 +1,21 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "java"
|
id "java"
|
||||||
id "maven-publish"
|
id "maven-publish"
|
||||||
id "net.minecrell.plugin-yml.bukkit" version "0.6.1-SNAPSHOT"
|
id "com.github.johnrengelman.shadow" version "8.1.1"
|
||||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group = "dev.plex"
|
||||||
|
version = "1.3"
|
||||||
|
description = "Plex"
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
apply plugin: "java"
|
||||||
|
apply plugin: "maven-publish"
|
||||||
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://papermc.io/repo/repository/maven-public/")
|
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
@ -29,129 +36,20 @@ repositories {
|
|||||||
mavenCentral()
|
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"
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "dev.plex"
|
|
||||||
version = "1.0.3"
|
|
||||||
description = "Plex"
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
archiveClassifier.set("")
|
|
||||||
relocate "org.bstats", "dev.plex"
|
|
||||||
}
|
|
||||||
|
|
||||||
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", "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.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 {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
publishing {
|
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
|
def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
|
||||||
def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
||||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
url = rootProject.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
||||||
credentials {
|
credentials {
|
||||||
username = System.getenv("plexUser")
|
username = System.getenv("plexUser")
|
||||||
password = System.getenv("plexPassword")
|
password = System.getenv("plexPassword")
|
||||||
@ -159,18 +57,16 @@ publishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
options.encoding = "UTF-8"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
clean {
|
||||||
build {
|
dependsOn(":server:clean")
|
||||||
dependsOn(shadowJar)
|
dependsOn(":proxy:clean")
|
||||||
finalizedBy(buildProperties)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
javadoc {
|
task copyJars(type: Copy, dependsOn: subprojects.jar) {
|
||||||
options.memberLevel = JavadocMemberLevel.PRIVATE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
}
|
from(subprojects.jar)
|
||||||
|
from(subprojects.shadowJar)
|
||||||
|
into project.file('build/libs')
|
||||||
}
|
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
18
gradlew
vendored
18
gradlew
vendored
@ -55,7 +55,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@ -80,10 +80,10 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
@ -143,12 +143,16 @@ fi
|
|||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@ -205,6 +209,12 @@ set -- \
|
|||||||
org.gradle.wrapper.GradleWrapperMain \
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
# Use "xargs" to parse quoted args.
|
||||||
#
|
#
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
11
gradlew.bat
vendored
11
gradlew.bat
vendored
@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
|
|||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
45
proxy/build.gradle.kts
Normal file
45
proxy/build.gradle.kts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
plugins {
|
||||||
|
id("net.kyori.blossom") version "1.3.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = rootProject.group
|
||||||
|
version = rootProject.version
|
||||||
|
description = "Plex-Velocity"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("https://repo.papermc.io/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.28")
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||||
|
compileOnly("org.json:json:20230618")
|
||||||
|
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||||
|
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||||
|
}
|
82
proxy/src/main/java/dev/plex/Plex.java
Normal file
82
proxy/src/main/java/dev/plex/Plex.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
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 lombok.Getter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
103
proxy/src/main/java/dev/plex/command/PlexCommand.java
Normal file
103
proxy/src/main/java/dev/plex/command/PlexCommand.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
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 net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
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,28 @@
|
|||||||
|
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
|
||||||
|
}
|
100
proxy/src/main/java/dev/plex/config/TomlConfig.java
Normal file
100
proxy/src/main/java/dev/plex/config/TomlConfig.java
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
package dev.plex.config;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.toml.Toml;
|
||||||
|
import dev.plex.toml.TomlWriter;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
proxy/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
33
proxy/src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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,63 @@
|
|||||||
|
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 net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
28
proxy/src/main/java/dev/plex/settings/ServerSettings.java
Normal file
28
proxy/src/main/java/dev/plex/settings/ServerSettings.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package dev.plex.settings;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
83
proxy/src/main/java/dev/plex/toml/ArrayValueWriter.java
Normal file
83
proxy/src/main/java/dev/plex/toml/ArrayValueWriter.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
91
proxy/src/main/java/dev/plex/toml/ObjectValueWriter.java
Normal file
91
proxy/src/main/java/dev/plex/toml/ObjectValueWriter.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
356
proxy/src/main/java/dev/plex/toml/Results.java
Normal file
356
proxy/src/main/java/dev/plex/toml/Results.java
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
39
proxy/src/main/java/dev/plex/toml/TableArrayValueWriter.java
Normal file
39
proxy/src/main/java/dev/plex/toml/TableArrayValueWriter.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
489
proxy/src/main/java/dev/plex/toml/Toml.java
Normal file
489
proxy/src/main/java/dev/plex/toml/Toml.java
Normal file
@ -0,0 +1,489 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
182
proxy/src/main/java/dev/plex/toml/TomlWriter.java
Normal file
182
proxy/src/main/java/dev/plex/toml/TomlWriter.java
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
package dev.plex.toml;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
41
proxy/src/main/java/dev/plex/toml/ValueReaders.java
Normal file
41
proxy/src/main/java/dev/plex/toml/ValueReaders.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package dev.plex.util;
|
package dev.plex.util;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.settings.ServerSettings;
|
||||||
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 org.bukkit.Bukkit;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
public class PlexLog
|
public class PlexLog
|
||||||
{
|
{
|
||||||
@ -17,12 +17,12 @@ public class PlexLog
|
|||||||
message = message.replace("{" + i + "}", strings[i].toString());
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.YELLOW + "[Plex] " + ChatColor.GRAY + "%s", message));
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<yellow>[Plex] <gray>" + message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(Component component)
|
public static void log(Component component)
|
||||||
{
|
{
|
||||||
Bukkit.getConsoleSender().sendMessage(Component.text("[Plex] ").color(NamedTextColor.YELLOW).append(component).colorIfAbsent(NamedTextColor.GRAY));
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(Component.text("[Plex] ").color(NamedTextColor.YELLOW).append(component).colorIfAbsent(NamedTextColor.GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(String message, Object... strings)
|
public static void error(String message, Object... strings)
|
||||||
@ -34,8 +34,7 @@ public class PlexLog
|
|||||||
message = message.replace("{" + i + "}", strings[i].toString());
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<red>[Plex Error] <gold>" + message));
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<red>[Plex Error] <gold>" + message));
|
||||||
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error] " + ChatColor.GOLD + "%s", message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(String message, Object... strings)
|
public static void warn(String message, Object... strings)
|
||||||
@ -47,8 +46,7 @@ public class PlexLog
|
|||||||
message = message.replace("{" + i + "}", strings[i].toString());
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.YELLOW + "[Plex Warning] " + ChatColor.GOLD + "%s", message));
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
|
||||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String message, Object... strings)
|
public static void debug(String message, Object... strings)
|
||||||
@ -60,10 +58,9 @@ public class PlexLog
|
|||||||
message = message.replace("{" + i + "}", strings[i].toString());
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Plex.get().config.getBoolean("debug"))
|
if (Plex.get().getConfig().as(ServerSettings.class).getServer().isDebug())
|
||||||
{
|
{
|
||||||
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<dark_purple>[Plex Debug] <gold>" + message));
|
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<dark_purple>[Plex Debug] <gold>" + message));
|
||||||
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.DARK_PURPLE + "[Plex Debug] " + ChatColor.GOLD + "%s", message));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package dev.plex.util;
|
package dev.plex.util;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class RandomUtil
|
public class RandomUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
public static NamedTextColor getRandomColor()
|
public static NamedTextColor getRandomColor()
|
||||||
{
|
{
|
||||||
NamedTextColor[] colors = NamedTextColor.NAMES.values().stream().filter(namedTextColor -> namedTextColor != NamedTextColor.BLACK && namedTextColor != NamedTextColor.DARK_BLUE).toArray(NamedTextColor[]::new);
|
NamedTextColor[] colors = NamedTextColor.NAMES.values().stream().filter(namedTextColor -> namedTextColor != NamedTextColor.BLACK && namedTextColor != NamedTextColor.DARK_BLUE).toArray(NamedTextColor[]::new);
|
@ -3,6 +3,7 @@ package dev.plex.util;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
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
|
146
server/build.gradle
Normal file
146
server/build.gradle
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
plugins {
|
||||||
|
id "net.minecrell.plugin-yml.paper" version "0.6.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
library "org.projectlombok:lombok:1.18.28"
|
||||||
|
annotationProcessor "org.projectlombok:lombok:1.18.28"
|
||||||
|
library "org.json:json:20230618"
|
||||||
|
library "commons-io:commons-io:2.13.0"
|
||||||
|
library "dev.morphia.morphia:morphia-core:2.3.5"
|
||||||
|
library "redis.clients:jedis:5.0.0-beta2"
|
||||||
|
library "org.mariadb.jdbc:mariadb-java-client:3.1.4"
|
||||||
|
library "com.zaxxer:HikariCP:5.0.1"
|
||||||
|
library "org.apache.maven.resolver:maven-resolver-transport-http:1.9.13"
|
||||||
|
compileOnly "dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT"
|
||||||
|
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
|
||||||
|
exclude group: "org.bukkit", module: "bukkit"
|
||||||
|
}
|
||||||
|
implementation "org.bstats:bstats-base:3.0.2"
|
||||||
|
implementation "org.bstats:bstats-bukkit:3.0.2"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = rootProject.group
|
||||||
|
version = rootProject.version
|
||||||
|
description = "Plex-Server"
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveBaseName.set("Plex")
|
||||||
|
archiveClassifier.set("")
|
||||||
|
relocate "org.bstats", "dev.plex"
|
||||||
|
}
|
||||||
|
|
||||||
|
paper {
|
||||||
|
name = "Plex"
|
||||||
|
version = project.version
|
||||||
|
description = "Plex provides a new experience for freedom servers."
|
||||||
|
main = "dev.plex.Plex"
|
||||||
|
loader = "dev.plex.PlexLibraryManager"
|
||||||
|
website = "https://plex.us.org"
|
||||||
|
authors = ["Telesphoreo", "taahanis", "supernt"]
|
||||||
|
apiVersion = "1.19"
|
||||||
|
foliaSupported = true
|
||||||
|
generateLibrariesJson = true
|
||||||
|
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
|
||||||
|
serverDependencies {
|
||||||
|
'BukkitTelnet' {
|
||||||
|
required = false
|
||||||
|
load = 'BEFORE'
|
||||||
|
}
|
||||||
|
'LibsDisguises' {
|
||||||
|
required = false
|
||||||
|
load = 'BEFORE'
|
||||||
|
}
|
||||||
|
'Vault' {
|
||||||
|
required = false
|
||||||
|
load = 'BEFORE'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,13 +22,16 @@ import dev.plex.storage.player.SQLPlayerData;
|
|||||||
import dev.plex.storage.punishment.SQLNotes;
|
import dev.plex.storage.punishment.SQLNotes;
|
||||||
import dev.plex.storage.punishment.SQLPunishment;
|
import dev.plex.storage.punishment.SQLPunishment;
|
||||||
import dev.plex.util.BuildInfo;
|
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.util.redis.MessageUtil;
|
||||||
import dev.plex.world.CustomWorld;
|
import dev.plex.world.CustomWorld;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.milkbowl.vault.chat.Chat;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -39,22 +42,21 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
@Setter
|
@Setter
|
||||||
public class Plex extends JavaPlugin
|
public class Plex extends JavaPlugin
|
||||||
{
|
{
|
||||||
|
public static final BuildInfo build = new BuildInfo();
|
||||||
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 commands;
|
public Config commands;
|
||||||
|
public Config toggles;
|
||||||
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;
|
||||||
|
|
||||||
@ -72,6 +74,7 @@ public class Plex extends JavaPlugin
|
|||||||
private String system;
|
private String system;
|
||||||
|
|
||||||
private Permission permissions;
|
private Permission permissions;
|
||||||
|
private Chat chat;
|
||||||
|
|
||||||
public static Plex get()
|
public static Plex get()
|
||||||
{
|
{
|
||||||
@ -81,11 +84,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");
|
||||||
commands = 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");
|
||||||
@ -97,6 +102,8 @@ 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
|
||||||
@ -104,7 +111,9 @@ 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);
|
||||||
commands.load(false);
|
commands.load(false);
|
||||||
|
|
||||||
@ -112,7 +121,7 @@ public class Plex extends JavaPlugin
|
|||||||
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");
|
||||||
|
|
||||||
@ -128,11 +137,17 @@ public class Plex extends JavaPlugin
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!setupPermissions() && system.equalsIgnoreCase("permissions") && !getServer().getPluginManager().isPluginEnabled("Vault"))
|
if (system.equals("permissions"))
|
||||||
|
{
|
||||||
|
if (!getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
permissions = setupPermissions();
|
||||||
|
chat = setupChat();
|
||||||
|
}
|
||||||
|
|
||||||
updateChecker = new UpdateChecker();
|
updateChecker = new UpdateChecker();
|
||||||
PlexLog.log("Update checking enabled");
|
PlexLog.log("Update checking enabled");
|
||||||
|
|
||||||
@ -144,6 +159,8 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
redisConnection.getJedis();
|
redisConnection.getJedis();
|
||||||
PlexLog.log("Connected to Redis!");
|
PlexLog.log("Connected to Redis!");
|
||||||
|
MessageUtil.subscribe();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -175,7 +192,11 @@ public class Plex extends JavaPlugin
|
|||||||
punishmentManager.mergeIndefiniteBans();
|
punishmentManager.mergeIndefiniteBans();
|
||||||
PlexLog.log("Punishment System initialized");
|
PlexLog.log("Punishment System initialized");
|
||||||
|
|
||||||
|
if (!PlexUtils.isFolia())
|
||||||
|
{
|
||||||
|
// World generation is not supported on Folia yet
|
||||||
generateWorlds();
|
generateWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
serviceManager = new ServiceManager();
|
serviceManager = new ServiceManager();
|
||||||
PlexLog.log("Service Manager initialized");
|
PlexLog.log("Service Manager initialized");
|
||||||
@ -183,6 +204,16 @@ 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");
|
||||||
|
|
||||||
|
moduleManager.enableModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -190,7 +221,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))
|
||||||
{
|
{
|
||||||
@ -212,6 +243,8 @@ public class Plex extends JavaPlugin
|
|||||||
redisConnection.getJedis().close();
|
redisConnection.getJedis().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
|
||||||
|
|
||||||
moduleManager.disableModules();
|
moduleManager.disableModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +263,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());
|
||||||
@ -241,10 +274,17 @@ public class Plex extends JavaPlugin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setupPermissions()
|
private Permission setupPermissions()
|
||||||
{
|
{
|
||||||
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
|
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
|
||||||
permissions = rsp.getProvider();
|
permissions = rsp.getProvider();
|
||||||
return permissions != null;
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Chat setupChat()
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = Bukkit.getServicesManager().getRegistration(Chat.class);
|
||||||
|
chat = rsp.getProvider();
|
||||||
|
return chat;
|
||||||
}
|
}
|
||||||
}
|
}
|
66
server/src/main/java/dev/plex/PlexLibraryManager.java
Normal file
66
server/src/main/java/dev/plex/PlexLibraryManager.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package dev.plex;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
|
||||||
|
import io.papermc.paper.plugin.loader.PluginLoader;
|
||||||
|
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
|
||||||
|
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||||
|
import org.eclipse.aether.graph.Dependency;
|
||||||
|
import org.eclipse.aether.repository.RemoteRepository;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class PlexLibraryManager implements PluginLoader
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||||
|
PluginLibraries pluginLibraries = load();
|
||||||
|
pluginLibraries.asDependencies().forEach(resolver::addDependency);
|
||||||
|
pluginLibraries.asRepositories().forEach(resolver::addRepository);
|
||||||
|
// The plugin is null, a hacky way to check whether to load Jetty or not
|
||||||
|
if (new File("plugins/Plex/modules/Plex-HTTPD.jar").isFile())
|
||||||
|
{
|
||||||
|
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-server:11.0.15"), null));
|
||||||
|
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-servlet:11.0.15"), null));
|
||||||
|
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-proxy:11.0.15"), null));
|
||||||
|
}
|
||||||
|
classpathBuilder.addLibrary(resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginLibraries load()
|
||||||
|
{
|
||||||
|
try (var in = getClass().getResourceAsStream("/paper-libraries.json"))
|
||||||
|
{
|
||||||
|
return new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), PluginLibraries.class);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record PluginLibraries(Map<String, String> repositories, List<String> dependencies)
|
||||||
|
{
|
||||||
|
public Stream<Dependency> asDependencies()
|
||||||
|
{
|
||||||
|
return dependencies.stream()
|
||||||
|
.map(d -> new Dependency(new DefaultArtifact(d), null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<RemoteRepository> asRepositories()
|
||||||
|
{
|
||||||
|
return repositories.entrySet().stream()
|
||||||
|
.map(e -> new RemoteRepository.Builder(e.getKey(), "default", e.getValue()).build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,12 @@
|
|||||||
package dev.plex.admin;
|
package dev.plex.admin;
|
||||||
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin object to handle cached admins
|
* Admin object to handle cached admins
|
||||||
*/
|
*/
|
@ -10,6 +10,7 @@ import dev.plex.PlexBase;
|
|||||||
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.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
@ -3,6 +3,8 @@ package dev.plex.cache;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,9 +51,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)
|
||||||
{
|
{
|
||||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
if (Plex.get().getPlayerCache().getPlexPlayerMap().containsKey(uuid))
|
||||||
|
{
|
||||||
|
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
@ -60,19 +67,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +103,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;
|
@ -2,6 +2,7 @@ package dev.plex.cache;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
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;
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ public class PlayerCache
|
|||||||
// {
|
// {
|
||||||
// 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,21 +2,14 @@ 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.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.CommandFailException;
|
import dev.plex.command.exception.*;
|
||||||
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;
|
||||||
@ -24,15 +17,14 @@ 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.Command;
|
import org.bukkit.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
|
||||||
*/
|
*/
|
||||||
@ -66,7 +58,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);
|
||||||
@ -83,8 +75,16 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
this.level = perms.level();
|
this.level = perms.level();
|
||||||
this.commandSource = perms.source();
|
this.commandSource = perms.source();
|
||||||
|
|
||||||
|
if (register)
|
||||||
|
{
|
||||||
getMap().register("plex", this);
|
getMap().register("plex", this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlexCommand()
|
||||||
|
{
|
||||||
|
this(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the command
|
* Executes the command
|
||||||
@ -123,7 +123,12 @@ 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 (plexPlayer == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
@ -143,7 +148,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (!player.hasPermission(perms.permission()))
|
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||||
return true;
|
return true;
|
||||||
@ -179,7 +184,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (!plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getUuid()), perms.permission()))
|
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||||
return true;
|
return true;
|
||||||
@ -298,7 +303,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (!plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getUuid()), permission))
|
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||||
}
|
}
|
||||||
@ -336,7 +341,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
if (!player.hasPermission(permission))
|
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||||
}
|
}
|
||||||
@ -357,7 +362,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
return player.hasPermission(permission);
|
return !perms.permission().isEmpty() && player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -398,7 +403,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
return player.hasPermission(permission);
|
return !perms.permission().isEmpty() && player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -510,6 +515,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
|
||||||
*
|
*
|
||||||
@ -546,6 +563,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)
|
||||||
{
|
{
|
||||||
@ -557,7 +584,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();
|
@ -2,6 +2,7 @@ package dev.plex.command.annotation;
|
|||||||
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
@ -1,10 +1,11 @@
|
|||||||
package dev.plex.command.blocking;
|
package dev.plex.command.blocking;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.List;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class BlockedCommand
|
public class BlockedCommand
|
||||||
{
|
{
|
@ -15,16 +15,17 @@ 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.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
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;
|
||||||
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.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "admin", usage = "/<command> <add <player> | remove <player> | setrank <player> <rank> | list>", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
@CommandParameters(name = "admin", usage = "/<command> <add <player> | remove <player> | setrank <player> <rank> | list>", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
||||||
@System(value = "ranks")
|
@System(value = "ranks")
|
46
server/src/main/java/dev/plex/command/impl/AdminChatCMD.java
Normal file
46
server/src/main/java/dev/plex/command/impl/AdminChatCMD.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
|
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.player.PlexPlayer;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
|
import dev.plex.util.redis.MessageUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminchat", source = RequiredCommandSource.ANY)
|
||||||
|
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
|
||||||
|
public class AdminChatCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
if (playerSender != null)
|
||||||
|
{
|
||||||
|
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
|
||||||
|
player.setStaffChat(!player.isStaffChat());
|
||||||
|
return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat()));
|
||||||
|
}
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = StringUtils.join(args, " ");
|
||||||
|
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), message));
|
||||||
|
MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), message).toArray(UUID[]::new));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,6 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.event.GameModeUpdateEvent;
|
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 net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -18,8 +17,10 @@ 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.List;
|
||||||
|
|
||||||
@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
|
||||||
@ -29,7 +30,7 @@ public class AdventureCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
|
||||||
}
|
}
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE));
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE));
|
||||||
return null;
|
return null;
|
@ -12,23 +12,20 @@ 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.PlexLog;
|
import dev.plex.util.*;
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.TimeUtils;
|
|
||||||
import dev.plex.util.WebUtils;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
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.lang3.StringUtils;
|
||||||
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;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||||
|
|
||||||
@ -101,7 +98,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;
|
@ -22,7 +22,7 @@ public class CommandSpyCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (playerSender != null)
|
if (playerSender != null)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(playerSender.getUniqueId());
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||||
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
|
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
|
||||||
DataUtils.update(plexPlayer);
|
DataUtils.update(plexPlayer);
|
||||||
send(sender, messageComponent("toggleCommandSpy")
|
send(sender, messageComponent("toggleCommandSpy")
|
@ -7,7 +7,7 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
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 org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
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;
|
@ -9,7 +9,6 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.event.GameModeUpdateEvent;
|
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 net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -18,8 +17,10 @@ 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.List;
|
||||||
|
|
||||||
@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
|
||||||
@ -29,7 +30,7 @@ public class CreativeCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
|
||||||
}
|
}
|
||||||
if (!(playerSender == null))
|
if (!(playerSender == null))
|
||||||
{
|
{
|
@ -9,9 +9,6 @@ import dev.plex.rank.enums.Rank;
|
|||||||
import dev.plex.util.GameRuleUtil;
|
import dev.plex.util.GameRuleUtil;
|
||||||
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.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
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 org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -22,6 +19,10 @@ 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.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
||||||
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
||||||
@System(debug = true)
|
@System(debug = true)
|
||||||
@ -35,6 +36,8 @@ public class DebugCMD extends PlexCommand
|
|||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("redis-reset"))
|
if (args[0].equalsIgnoreCase("redis-reset"))
|
||||||
|
{
|
||||||
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
Player player = getNonNullPlayer(args[1]);
|
Player player = getNonNullPlayer(args[1]);
|
||||||
if (plugin.getRedisConnection().getJedis().exists(player.getUniqueId().toString()))
|
if (plugin.getRedisConnection().getJedis().exists(player.getUniqueId().toString()))
|
||||||
@ -44,6 +47,7 @@ public class DebugCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return componentFromString("Couldn't find player in Redis punishments.");
|
return componentFromString("Couldn't find player in Redis punishments.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (args[0].equalsIgnoreCase("gamerules"))
|
if (args[0].equalsIgnoreCase("gamerules"))
|
||||||
{
|
{
|
||||||
for (World world : Bukkit.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
@ -63,6 +67,8 @@ public class DebugCMD extends PlexCommand
|
|||||||
return mmString("<aqua>Re-applied game all the game rules!");
|
return mmString("<aqua>Re-applied game all the game rules!");
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("aliases"))
|
if (args[0].equalsIgnoreCase("aliases"))
|
||||||
|
{
|
||||||
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
String commandName = args[1];
|
String commandName = args[1];
|
||||||
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
|
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
|
||||||
@ -72,7 +78,8 @@ public class DebugCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
|
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -7,13 +7,14 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.annotation.System;
|
import dev.plex.command.annotation.System;
|
||||||
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 net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
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;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "deop", description = "Deop a player on the server", usage = "/<command> <player>")
|
@CommandParameters(name = "deop", description = "Deop a player on the server", usage = "/<command> <player>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.deop")
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.deop")
|
||||||
@System(value = "ranks")
|
@System(value = "ranks")
|
@ -6,11 +6,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
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.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -21,6 +16,8 @@ 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.*;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [name]", aliases = "ew,rd")
|
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [name]", aliases = "ew,rd")
|
||||||
public class EntityWipeCMD extends PlexCommand
|
public class EntityWipeCMD extends PlexCommand
|
@ -9,11 +9,6 @@ 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.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -21,6 +16,10 @@ 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.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
|
||||||
public class FreezeCMD extends PlexCommand
|
public class FreezeCMD extends PlexCommand
|
104
server/src/main/java/dev/plex/command/impl/GamemodeCMD.java
Normal file
104
server/src/main/java/dev/plex/command/impl/GamemodeCMD.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
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.exception.CommandFailException;
|
||||||
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
|
||||||
|
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||||
|
public class GamemodeCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
private GameMode gamemode;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
switch (args[0].toLowerCase())
|
||||||
|
{
|
||||||
|
case "survival", "s", "0" ->
|
||||||
|
{
|
||||||
|
gamemode = GameMode.SURVIVAL;
|
||||||
|
update(sender, playerSender, GameMode.SURVIVAL);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "creative", "c", "1" ->
|
||||||
|
{
|
||||||
|
gamemode = GameMode.CREATIVE;
|
||||||
|
update(sender, playerSender, GameMode.CREATIVE);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "adventure", "a", "2" ->
|
||||||
|
{
|
||||||
|
gamemode = GameMode.ADVENTURE;
|
||||||
|
update(sender, playerSender, GameMode.ADVENTURE);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "default", "d", "5" ->
|
||||||
|
{
|
||||||
|
gamemode = plugin.getServer().getDefaultGameMode();
|
||||||
|
update(sender, playerSender, plugin.getServer().getDefaultGameMode());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "spectator", "sp", "3", "6" ->
|
||||||
|
{
|
||||||
|
gamemode = GameMode.SPECTATOR;
|
||||||
|
checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator");
|
||||||
|
update(sender, playerSender, GameMode.SPECTATOR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args.length > 1)
|
||||||
|
{
|
||||||
|
checkRank(sender, Rank.ADMIN, "plex.gamemode.others");
|
||||||
|
Player player = getNonNullPlayer(args[1]);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update(CommandSender sender, Player playerSender, GameMode gameMode)
|
||||||
|
{
|
||||||
|
if (isConsole(sender))
|
||||||
|
{
|
||||||
|
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||||
|
}
|
||||||
|
if (!(playerSender == null))
|
||||||
|
{
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender.getPlayer(), gameMode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
return Arrays.asList("creative", "survival", "adventure", "spectator", "default");
|
||||||
|
}
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
return PlexUtils.getPlayerNameList();
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
@ -10,21 +10,22 @@ 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.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.WebUtils;
|
import dev.plex.util.WebUtils;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
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.lang3.StringUtils;
|
||||||
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;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||||
public class KickCMD extends PlexCommand
|
public class KickCMD extends PlexCommand
|
||||||
@ -56,9 +57,9 @@ public class KickCMD extends PlexCommand
|
|||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
reason = StringUtils.join(args, " ", 1, args.length);
|
reason = StringUtils.join(args, " ", 1, args.length);
|
||||||
punishment.setReason(reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
punishment.setReason(reason);
|
||||||
punishment.setPunishedUsername(plexPlayer.getName());
|
punishment.setPunishedUsername(plexPlayer.getName());
|
||||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||||
punishment.setCustomTime(false);
|
punishment.setCustomTime(false);
|
||||||
@ -66,7 +67,7 @@ public class KickCMD extends PlexCommand
|
|||||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||||
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
||||||
player.kick(componentFromString(reason));
|
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,9 +4,8 @@ import com.google.common.collect.Lists;
|
|||||||
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.annotation.System;
|
import dev.plex.hook.VaultHook;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import java.util.List;
|
|
||||||
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 org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -15,9 +14,10 @@ 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;
|
||||||
|
|
||||||
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit")
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit,who,playerlist,online")
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
||||||
@System(value = "ranks")
|
|
||||||
public class ListCMD extends PlexCommand
|
public class ListCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -44,7 +44,14 @@ public class ListCMD extends PlexCommand
|
|||||||
for (int i = 0; i < players.size(); i++)
|
for (int i = 0; i < players.size(); i++)
|
||||||
{
|
{
|
||||||
Player player = players.get(i);
|
Player player = players.get(i);
|
||||||
|
if (plugin.getSystem().equals("ranks"))
|
||||||
|
{
|
||||||
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = list.append(VaultHook.getPrefix(getPlexPlayer(player))).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||||
|
}
|
||||||
if (i != players.size() - 1)
|
if (i != players.size() - 1)
|
||||||
{
|
{
|
||||||
list = list.append(Component.text(",")).append(Component.space());
|
list = list.append(Component.text(",")).append(Component.space());
|
@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.spawnpoint", source = RequiredCommandSource.IN_GAME)
|
@CommandPermissions(level = Rank.OP, permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
||||||
public class LocalSpawnCMD extends PlexCommand
|
public class LocalSpawnCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
@ -7,13 +7,14 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
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 dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
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;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
|
||||||
public class LockupCMD extends PlexCommand
|
public class LockupCMD extends PlexCommand
|
||||||
@ -42,6 +43,10 @@ public class LockupCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
|
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
|
||||||
|
if (punishedPlayer.isLockedUp())
|
||||||
|
{
|
||||||
|
player.openInventory(player.getInventory());
|
||||||
|
}
|
||||||
PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedPlayer", sender.getName(), player.getName()));
|
PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedPlayer", sender.getName(), player.getName()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -49,6 +54,6 @@ public class LockupCMD extends PlexCommand
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
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.HashMap;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -17,6 +16,8 @@ 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.HashMap;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp")
|
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp")
|
||||||
public class MobPurgeCMD extends PlexCommand
|
public class MobPurgeCMD extends PlexCommand
|
@ -9,11 +9,6 @@ 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.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -21,6 +16,10 @@ 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.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute")
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute")
|
||||||
public class MuteCMD extends PlexCommand
|
public class MuteCMD extends PlexCommand
|
||||||
@ -40,17 +39,10 @@ public class MuteCMD extends PlexCommand
|
|||||||
return messageComponent("playerMuted");
|
return messageComponent("playerMuted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAdmin(getPlexPlayer(player)))
|
if (silentCheckRank(player, Rank.ADMIN, "plex.mute"))
|
||||||
{
|
{
|
||||||
if (!isConsole(sender))
|
send(sender, messageComponent("higherRankThanYou"));
|
||||||
{
|
return null;
|
||||||
assert playerSender != null;
|
|
||||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
|
||||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
|
|
||||||
{
|
|
||||||
return messageComponent("higherRankThanYou");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user