mirror of
https://github.com/CarmJos/BukkitJSONSerializer.git
synced 2026-06-04 16:48:18 +08:00
Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c98bb8304c | |||
| 777a8e1172 | |||
| ab7d0c8585 | |||
| bd9a52394a | |||
| 30ac72c7e7 | |||
| e67fce5a9c | |||
| 8f064e30fe | |||
| f564a71dba | |||
| 75223a3053 | |||
| 7408c812a1 | |||
| 997caae735 | |||
| 6c75b40baa | |||
| 1750f4ed15 | |||
| 60aa56a22f | |||
| 08f8ad5b9c | |||
| 8afb86d312 | |||
| 36b790543b | |||
| a78744824f | |||
| 8cb4ab2e0f | |||
| 9fbb7f6db9 | |||
| d3586305dc | |||
| af149bc6a2 | |||
| ce5033103b | |||
| b56efd844e | |||
| 85d412aaf2 | |||
| 1fc40d6071 | |||
| 02e9460722 | |||
| 818a851dc3 | |||
| 609fa6de4d | |||
| 22c320535b | |||
| 13d8bee7bb | |||
| cbf234f5c3 | |||
| 7e2f5c572f | |||
| 63caf30e30 | |||
| 05a713dc05 | |||
| 4de11528fc | |||
| 5473b2cad0 | |||
| b77622a5c4 | |||
| 910809093f | |||
| 763500eaf9 | |||
| e69f735658 | |||
| f69cf4766a | |||
| f3c2813864 | |||
| 7b2bc66caf | |||
| edf8898790 | |||
| 8f0b1fed5d | |||
| b086d0adb1 | |||
| ed01643746 | |||
| 98eaae106a | |||
| eeecd57011 | |||
| c9a9c37881 | |||
| fc3839297f | |||
| 3bb9223322 | |||
| 4f2e8c2481 | |||
| 7c89dc0da6 | |||
| ace519609b | |||
| 3b386a97a8 | |||
| 19f1dca7a3 | |||
| 75886870f1 | |||
| d715fbf0ff | |||
| 4c773b5f8a | |||
| 6f803b7549 | |||
| 29d85f3791 | |||
| 51ed9eaf25 | |||
| cb3c96bdac | |||
| 927277183c | |||
| 2f8cd2be26 | |||
| 908bff5c96 | |||
| bc5289a8ce | |||
| 4b6bce533b | |||
| 9b5e13c1b1 | |||
| ebbb42ebee | |||
| 9fd40dc929 | |||
| 76f1d7dc06 | |||
| 52b3c38f78 | |||
| 4f558c5731 | |||
| ed49c067b8 | |||
| 49d260ffae | |||
| 6f4a51997d | |||
| dd44772fbc | |||
| 7ac3516daa | |||
| 2264c4af48 | |||
| f4e391f1d0 | |||
| 3e1399ebf6 | |||
| b5ad3541b8 | |||
| ea54bc7af7 | |||
| a1d6485e4c | |||
| 081b95854b | |||
| 9a0f4059ef | |||
| 8de886adbb | |||
| 5707d62af4 | |||
| 1937b0e9e1 |
@@ -0,0 +1,2 @@
|
|||||||
|
github: [ CarmJos ]
|
||||||
|
custom: [ 'https://donate.carm.cc' ]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "maven" # See documentation for possible values
|
||||||
|
directory: "/" # Location of package manifests
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
|
||||||
|
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
|
||||||
|
OK7d0W/LdJ3iFeselROADHgPQn14sg==
|
||||||
|
=rRA5
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
|
name: "Project Deploy"
|
||||||
|
|
||||||
|
on:
|
||||||
|
# 支持手动触发构建
|
||||||
|
workflow_dispatch:
|
||||||
|
release:
|
||||||
|
# 创建release的时候触发
|
||||||
|
types: [ published ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
packages-deploy:
|
||||||
|
name: "Publish Project (GitHub Packages)"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- name: "Set up JDK"
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
server-id: github
|
||||||
|
server-username: MAVEN_USERNAME
|
||||||
|
server-password: MAVEN_TOKEN
|
||||||
|
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||||
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||||
|
|
||||||
|
- name: "Packages Deploy"
|
||||||
|
run: mvn -B -Pgithub deploy --file pom.xml -DskipTests
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||||
|
|
||||||
|
central-deploy:
|
||||||
|
name: "Deploy Project (Central Repository)"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- name: "Set up JDK"
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
server-id: ossrh
|
||||||
|
server-username: MAVEN_USERNAME
|
||||||
|
server-password: MAVEN_PASSWORD
|
||||||
|
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||||
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||||
|
|
||||||
|
- name: "Central Deploy"
|
||||||
|
run: mvn -B -Possrh deploy --file pom.xml -DskipTests
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
|
||||||
|
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASS }}
|
||||||
|
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||||
|
|
||||||
|
github-deploy:
|
||||||
|
name: "Deploy Project (GitHub Repository)"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- name: "Set up JDK"
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||||
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||||
|
|
||||||
|
- name: "Maven Deploy"
|
||||||
|
run: mvn -B -Plocal deploy --file pom.xml -DskipTests
|
||||||
|
env:
|
||||||
|
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||||
|
|
||||||
|
- name: "Copy artifacts"
|
||||||
|
run: |
|
||||||
|
rm -rf deploy
|
||||||
|
mkdir -vp deploy
|
||||||
|
cp -vrf $HOME/local-deploy/* deploy/
|
||||||
|
|
||||||
|
- name: "Configure Git"
|
||||||
|
env:
|
||||||
|
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
||||||
|
run: |
|
||||||
|
sudo timedatectl set-timezone "Asia/Shanghai"
|
||||||
|
mkdir -p ~/.ssh/
|
||||||
|
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||||
|
git config --global user.name '${{ github.repository_owner }}'
|
||||||
|
git config --global user.email '${{ github.repository_owner }}@users.noreply.github.com'
|
||||||
|
|
||||||
|
- name: "Commit&Push repository files"
|
||||||
|
run: |
|
||||||
|
cd deploy
|
||||||
|
git init
|
||||||
|
git remote add origin git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git
|
||||||
|
git checkout -b repo
|
||||||
|
git add -A
|
||||||
|
git commit -m "Maven project deployment."
|
||||||
|
git push origin HEAD:repo --force
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
|
name: Project Build & Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
# 支持手动触发构建
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- name: "Set up JDK"
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'adopt'
|
||||||
|
- name: "Package"
|
||||||
|
run: mvn -B package --file pom.xml -Dgpg.skip
|
||||||
|
- name: "Target Stage"
|
||||||
|
run: mkdir staging && cp target/*.jar staging
|
||||||
|
- name: "Upload artifact"
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: Artifact
|
||||||
|
path: staging
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/.idea/
|
||||||
|
/target/
|
||||||
|
**/target/
|
||||||
|
./*.iml
|
||||||
|
*.iml
|
||||||
|
**.iml
|
||||||
|
|
||||||
|
asset/
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
# BukkitJSONSerializer
|
||||||
|
|
||||||
|
[](https://github.com/CarmJos/BukkitJSONSerializer/releases)
|
||||||
|
[](https://www.gnu.org/licenses/lgpl-3.0.html)
|
||||||
|
[](https://github.com/CarmJos/BukkitJSONSerializer/actions/workflows/maven.yml)
|
||||||
|
[](https://www.codefactor.io/repository/github/carmjos/BukkitJSONSerializer)
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
A JSON serialize/deserialize util for bukkit's ConfigurationSerialization.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Basic usage
|
||||||
|
|
||||||
|
First, we should get the serializer instance or create a new one.
|
||||||
|
|
||||||
|
```java
|
||||||
|
BukkitJSONSerializer serializer = BukkitJSONSerializer.get();
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, we could use `serializeToJSON(ConfigurationSerializable)` to serialize a object to JSON.
|
||||||
|
|
||||||
|
```jave
|
||||||
|
Location location = new Location(Bukkit.getWorlds().get(0), -100.5, 100, 105.5);
|
||||||
|
String serialized = serializer.serializeToJSON(location);
|
||||||
|
// -> {"world":"world","x":-100.5,"y":100,"z":105.5,"yaw":0.0,"pitch":0.0}
|
||||||
|
```
|
||||||
|
|
||||||
|
When we need to read the object, just use `deserializeJSON(json,typeClass)` to deserialize the JSON
|
||||||
|
string.
|
||||||
|
|
||||||
|
```java
|
||||||
|
Location location = serializer.deserializeJSON(json, Location.class);
|
||||||
|
// Location{world=world, x=-100.5, y=100, z=105.5, pitch=0.0, yaw=0.0}
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use `deserializeSON(json,typeClass,defaultValue)` if we need a default value.
|
||||||
|
|
||||||
|
### JSONSerializable class
|
||||||
|
|
||||||
|
This project provided an interface `JSONSerializable` which provided a default method to serialize itself to JSON.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public interface JSONSerializable extends ConfigurationSerializable {
|
||||||
|
|
||||||
|
default @NotNull String serializeToJSON() {
|
||||||
|
return BukkitJSONSerializer.serializeToJSON(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dependency Usage
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Maven dependency</summary>
|
||||||
|
|
||||||
|
```xml
|
||||||
|
|
||||||
|
<project>
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--Using central repository-->
|
||||||
|
<id>maven</id>
|
||||||
|
<name>Maven Central</name>
|
||||||
|
<url>https://repo1.maven.org/maven2</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--Using github repository-->
|
||||||
|
<id>BukkitJSONSerializer</id>
|
||||||
|
<url>https://raw.githubusercontent.com/CarmJos/BukkitJSONSerializer/repo/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>bukkitjsonserializer</artifactId>
|
||||||
|
<version>[LATEST RELEASE]</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Gradle dependency</summary>
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
repositories {
|
||||||
|
|
||||||
|
mavenCentral() // Using central repository.
|
||||||
|
|
||||||
|
// Using github repositories.
|
||||||
|
maven { url 'https://raw.githubusercontent.com/CarmJos/BukkitJSONSerializer/repo/' }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api "cc.carm.lib:bukkitjsonserializer:[LATEST RELEASE]"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## Open Source License.
|
||||||
|
|
||||||
|
The project using [GNU LESSER GENERAL PUBLIC LICENSE](https://www.gnu.org/licenses/lgpl-3.0.html) .
|
||||||
Binary file not shown.
@@ -1,14 +0,0 @@
|
|||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
|
|
||||||
iQGzBAABCgAdFiEEL6NL2WG27xbAlAIkh337tzeYbfcFAmLkHSkACgkQh337tzeY
|
|
||||||
bfeKngv+LN9JQDcuKDuIsqgGzxxAkWX0I6eybL8fo8rF0ECo990g7G3ORU5aRvG2
|
|
||||||
KazakfGyU8gqEgWU6bUI1HfR+MiyMlPmozvcewstBO6NZc2O63KSMAs03n69eHW8
|
|
||||||
it/+aI+YdLWl1rHHL1rBeXeo+FV8LvaVdWkhFjTuOaXV8oIII/6c+DGPc5QQgeFa
|
|
||||||
KbOrY8stqC9R+4IXOIucdoUVhEK3+cMOAebs3emYkEDvcB2O2Chqd++czR1nmToT
|
|
||||||
GziHZzJ8sooQQCQN1P613fHgdDoZloTD0773JsohvqIDXfrXkc8tgYgm7bJmaWIq
|
|
||||||
iAdpDnALRVP/vsJWgc/TBEc2RTDUF5M5Bs+IfX5Xk+gmGiKB1zcIHVOJuqJPerP+
|
|
||||||
lVc6oDyuhEw7t8mf1ogXntBz/YgERHcZIkF/4NIn4K27Cqs+anHLpsq1o8bqkc3d
|
|
||||||
iH2CrQrXaXacXUEZ7rpwKZXcYzT6eaIj6xgHoL6xyy8Quk5SEhZiy6w7oDBGr17E
|
|
||||||
YogljvQz
|
|
||||||
=jdHI
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
b9184eccece56883777fcd08c92afaf4
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
c9a5c836e9f234ed21419613575088c2509ad4f4
|
|
||||||
Binary file not shown.
@@ -1,14 +0,0 @@
|
|||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
|
|
||||||
iQGzBAABCgAdFiEEL6NL2WG27xbAlAIkh337tzeYbfcFAmLkHSoACgkQh337tzeY
|
|
||||||
bfdCUQv7BosyL3B5rZrux1Ia//S59V2Z/yQljurGUR6g2IIQ+0UfduvN5EBBcHX2
|
|
||||||
CWJJIEJ25HqfYDWEQl+c2LGw/ZMtIovu84+eSCrBvQnbjv2SM9fMpCzienE0ixbR
|
|
||||||
LlGkvi2/smng37kw1D53aMtKBqA4T93K8SuQv+9EoKNsv67RPCmfNpeVO3JFmKi2
|
|
||||||
sO99cQjXGc40aT4ckPvBe17d3g1FmNsBVY66dTeN5D5tag2tGAlLe0d9piMq+wDi
|
|
||||||
IkPE4xiu2qwpDVMIo9wXP+WdQPKYK+a+yCjiDwVoQIumDe/bbJIfa0c4I9pGJMVu
|
|
||||||
v953hTilO/OWg8ezvi55/N4HeukdndQjcLUldZRUJzpsOv/w/mt4e4F3KavY3mIA
|
|
||||||
s6zpd2R/1u34ghESid2LTE3vXC0/yECDLwY7gh4C5xsAoPyjvuRIVWuCeZO1xAJu
|
|
||||||
s3eaa/RpTUTIpKlloTkjystvldIh/gIUZ3F7ZbF3t3+Qt6/wyJBwqWBG5Naj+C13
|
|
||||||
cDqJ4nDB
|
|
||||||
=h2XK
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
77e1c2570a15d78da347373d744e47f9
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
f9a34002163d83205f85e69ffcb309c33d80130e
|
|
||||||
Binary file not shown.
@@ -1,14 +0,0 @@
|
|||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
|
|
||||||
iQGzBAABCgAdFiEEL6NL2WG27xbAlAIkh337tzeYbfcFAmLkHSgACgkQh337tzeY
|
|
||||||
bfeG3Qv+IMXKVLTdGLlUgeRTrL1gAlfbJrD5ek8OUk+Dr25x06t3Gv3IytR8+h56
|
|
||||||
8fWxzetmvU5NJtqvlD8fr+McYNfcKFywRXXP7Q1/KVyK4+ouP61vCT7cuUQS+EaY
|
|
||||||
STU0/bS5rxYQ2GnGMHt3ZtCuDEydLveC5qwNaXH1OmuhJxbTLTU9d4/3iTpVZtUQ
|
|
||||||
avoJ2wIC7LOEctJN15TN9x4RiN8UPO8NMWKWTZHoapB45IwTDr6Ix8CjIsunsk+B
|
|
||||||
XDSo0ICelDUIz4PgoBA6kk48EWfJ3ZeClO8R70cm6qCdDCFM9JKULAbIgq4j87Wa
|
|
||||||
8/C102Kjlkx8vfbjXtI+mMCLczgA+a2nWDHzV2UZc0hvgtTjXTZL0Qh+68DsJ7K6
|
|
||||||
M9TEDQEztGOGg2xoIFQl8T3NafYD5MsvdCGBRPV88rf+cDP1mD3/hCNj0B0NxBac
|
|
||||||
b/dMm5LZnr6+Js4aCQIU8SBc9fL1s4s6bkYPN98JZWcWGITVI/Ddj81EgqaK6lzW
|
|
||||||
DcZPEHjJ
|
|
||||||
=MHMK
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
0f9cf276ae760ffd09758106975397dd
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
741b687c31895664c294110f725336157c9daaec
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
|
|
||||||
iQGzBAABCgAdFiEEL6NL2WG27xbAlAIkh337tzeYbfcFAmLkHSkACgkQh337tzeY
|
|
||||||
bfeGvwv/WAg55BgiXLWdayAgx26rakotW/R3c+tCqKuJZ1CQJEQeOdWHMeCsAf+M
|
|
||||||
dQSf7ZcK95kKtWauxaZ00zhRpyv1HPS+1lgXAEdnVLQ5cZBarOqY7EhzTMsOjfqJ
|
|
||||||
r61TLXfrioUTBOGIf7QWI5zwbDX2FOEK4Yuyd3+xf6tqKYzdOtAYTVI73D7Ia2y0
|
|
||||||
QzkWUS/31zVT3vEZ9OULdyTtxh77Nk4bgOQznlnmf/d6NgAYigcPf1dZwD8Ry7Rd
|
|
||||||
F1cnzYfrTWCqzJe8LujdGH1oTi/4rvJN+3mp+8Rkctrm3zrz+bsdzwtK+7B9Eo2R
|
|
||||||
yDiBM/oUfKAHXVWleXcqyGSN/xqEpFQuQKPYyKGD0ZPuqA66HZxLYHWkNBCJ0Crl
|
|
||||||
6f4L5ONu0jAHUMlXshnInxYwfAT9qMdlr7o7lSnrMBHQdTvaUXJkEC305QfBLL1N
|
|
||||||
4Ey6GnSoo4I4Q+bklyOj1BRRx06Vx5F5pDhUuFDyzDObkjMJD93tn2SzEwy3MTv3
|
|
||||||
BPZ29Kkp
|
|
||||||
=3fGJ
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
709b8420f224f4e2b48c2d79934e552a
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
e796e908a0366975470641ce92ebd797e0617310
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<metadata>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<artifactId>bukkitjsonserializer</artifactId>
|
|
||||||
<versioning>
|
|
||||||
<release>1.0.2</release>
|
|
||||||
<versions>
|
|
||||||
<version>1.0.2</version>
|
|
||||||
</versions>
|
|
||||||
<lastUpdated>20220729174602</lastUpdated>
|
|
||||||
</versioning>
|
|
||||||
</metadata>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
5e5234a8a0c075544dcf15ff0a7f281b
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
8d4ad1af784a5ad9c087e125c70af6a2e87f6fc9
|
|
||||||
@@ -81,14 +81,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
<version>1.17-R0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>23.0.0</version>
|
<version>26.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>3.5.6</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.12.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.10.1</version>
|
<version>3.15.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${jdk.version}</source>
|
<source>${jdk.version}</source>
|
||||||
<target>${jdk.version}</target>
|
<target>${jdk.version}</target>
|
||||||
@@ -153,12 +153,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.5.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
<version>3.4.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>3.2.8</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
@@ -191,7 +191,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
<version>2.5.3</version>
|
<version>3.3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||||
<useReleaseProfile>false</useReleaseProfile>
|
<useReleaseProfile>false</useReleaseProfile>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
package cc.carm.lib.bukkit.configuration;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BukkitJSONSerializer, a lightweight JSON serializer for {@link ConfigurationSerializable} objects.
|
||||||
|
* <ul>
|
||||||
|
* <li>serialize by {@link #serializeToJSON(ConfigurationSerializable)}</li>
|
||||||
|
* <li>deserialize by {@link #deserializeJSON(String, Class, ConfigurationSerializable)}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @author CarmJos
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public class BukkitJSONSerializer {
|
||||||
|
|
||||||
|
public static final String TYPE_KEY = ConfigurationSerialization.SERIALIZED_TYPE_KEY;
|
||||||
|
public static final BukkitJSONSerializer INSTANCE = BukkitJSONSerializer.create();
|
||||||
|
|
||||||
|
|
||||||
|
public static @NotNull BukkitJSONSerializer create() {
|
||||||
|
return create(new GsonBuilder().enableComplexMapKeySerialization().serializeNulls().disableHtmlEscaping().create());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull BukkitJSONSerializer create(@NotNull Gson gson) {
|
||||||
|
return new BukkitJSONSerializer(gson, new JsonParser());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull BukkitJSONSerializer create(@NotNull Gson gson, @NotNull JsonParser parser) {
|
||||||
|
return new BukkitJSONSerializer(gson, parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull BukkitJSONSerializer get() {
|
||||||
|
return BukkitJSONSerializer.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull Gson gson;
|
||||||
|
protected final @NotNull JsonParser parser;
|
||||||
|
|
||||||
|
public BukkitJSONSerializer(@NotNull Gson gson, @NotNull JsonParser parser) {
|
||||||
|
this.gson = gson;
|
||||||
|
this.parser = parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes a {@link ConfigurationSerializable} object to Map.
|
||||||
|
*
|
||||||
|
* @param value object to serialize.
|
||||||
|
* @param <T> {@link ConfigurationSerializable} object type.
|
||||||
|
* @return Map containing serialized data
|
||||||
|
*/
|
||||||
|
public <T extends ConfigurationSerializable> Map<String, Object> serializeToMap(T value) {
|
||||||
|
Map<String, Object> values = new LinkedHashMap<>();
|
||||||
|
// First, put tye type key;
|
||||||
|
values.put(TYPE_KEY, ConfigurationSerialization.getAlias(value.getClass()));
|
||||||
|
// Then, put the serialized value
|
||||||
|
value.serialize().forEach((key, sub) -> {
|
||||||
|
if (sub instanceof ConfigurationSerializable) {
|
||||||
|
values.put(key, serializeToMap((ConfigurationSerializable) sub));
|
||||||
|
} else {
|
||||||
|
values.put(key, sub);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes a {@link ConfigurationSerializable} object to JSON.
|
||||||
|
*
|
||||||
|
* @param value object to serialize.
|
||||||
|
* @param <T> {@link ConfigurationSerializable} object type.
|
||||||
|
* @return JSON string containing serialized data.
|
||||||
|
*/
|
||||||
|
public <T extends ConfigurationSerializable> String serializeToJSON(T value) {
|
||||||
|
return gson.toJson(serializeToMap(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a {@link ConfigurationSerializable} object from JSON.
|
||||||
|
*
|
||||||
|
* @param json JSON string to deserialize.
|
||||||
|
* @return Deserialized object.
|
||||||
|
*/
|
||||||
|
@Contract("null->null")
|
||||||
|
public Object deserializeJSON(@Nullable String json) {
|
||||||
|
return deserializeJSON(json, (ConfigurationSerializable) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a {@link ConfigurationSerializable} object from JSON.
|
||||||
|
*
|
||||||
|
* @param json JSON string to deserialize.
|
||||||
|
* @param defaultValue default value to return if json is null or failed to deserialize.
|
||||||
|
* @return Deserialized object.
|
||||||
|
*/
|
||||||
|
@Contract("_,!null->!null; null,null->null")
|
||||||
|
public ConfigurationSerializable deserializeJSON(@Nullable String json,
|
||||||
|
@Nullable ConfigurationSerializable defaultValue) {
|
||||||
|
if (json == null) return defaultValue;
|
||||||
|
Map<String, Object> args = jsonToMap(json);
|
||||||
|
|
||||||
|
return Optional.ofNullable((String) args.get(TYPE_KEY))
|
||||||
|
.map(ConfigurationSerialization::getClassByAlias)
|
||||||
|
.map(clazz -> ConfigurationSerialization.deserializeObject(args, clazz))
|
||||||
|
.orElse(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a {@link ConfigurationSerializable} object from Map.
|
||||||
|
*
|
||||||
|
* @param json JSON string to deserialize.
|
||||||
|
* @param typeClazz type of object.
|
||||||
|
* @param <T> {@link ConfigurationSerializable} object type.
|
||||||
|
* @return Deserialized object.
|
||||||
|
*/
|
||||||
|
public <T extends ConfigurationSerializable> @Nullable T deserializeJSON(@Nullable String json,
|
||||||
|
@NotNull Class<T> typeClazz) {
|
||||||
|
return deserializeJSON(json, typeClazz, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a {@link ConfigurationSerializable} object from Map.
|
||||||
|
*
|
||||||
|
* @param json JSON string to deserialize.
|
||||||
|
* @param typeClazz type of object.
|
||||||
|
* @param defaultValue default value to return if json is null or failed to deserialize.
|
||||||
|
* @param <T> {@link ConfigurationSerializable} object type.
|
||||||
|
* @return Deserialized object.
|
||||||
|
*/
|
||||||
|
@Contract("_,_,!null->!null; null,_,null->null")
|
||||||
|
public <T extends ConfigurationSerializable> T deserializeJSON(@Nullable String json,
|
||||||
|
@NotNull Class<T> typeClazz,
|
||||||
|
@Nullable T defaultValue) {
|
||||||
|
Object value = deserializeJSON(json, defaultValue);
|
||||||
|
if (!typeClazz.isInstance(value)) return defaultValue;
|
||||||
|
|
||||||
|
return typeClazz.cast(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object> jsonToMap(String json) {
|
||||||
|
return jsonToMap(parser.parse(json).getAsJsonObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object> jsonToMap(JsonObject object) {
|
||||||
|
return parseMap(gson.fromJson(object, Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object> parseMap(Map<?, ?> map) {
|
||||||
|
Map<String, Object> args = new LinkedHashMap<>();
|
||||||
|
map.forEach((k, v) -> {
|
||||||
|
String key = (String) k;
|
||||||
|
if (v instanceof Map<?, ?>) {
|
||||||
|
Map<String, Object> sub = parseMap((Map<?, ?>) v);
|
||||||
|
if (sub.containsKey(TYPE_KEY)) {
|
||||||
|
args.put(key, ConfigurationSerialization.deserializeObject(sub));
|
||||||
|
} else {
|
||||||
|
args.put(key, sub);
|
||||||
|
}
|
||||||
|
} else if (v instanceof Double) {
|
||||||
|
double d = (Double) v;
|
||||||
|
BigDecimal num = new BigDecimal(d);
|
||||||
|
long longValue = num.longValue();
|
||||||
|
String decimalPart = String.valueOf(num.subtract(new BigDecimal(longValue)));
|
||||||
|
|
||||||
|
if (decimalPart.matches("^0+$")) {
|
||||||
|
if (longValue > Integer.MAX_VALUE || longValue < Integer.MIN_VALUE) {
|
||||||
|
args.put(key, num.longValue());
|
||||||
|
} else {
|
||||||
|
args.put(key, num.intValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
args.put(key, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package cc.carm.lib.bukkit.configuration;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface JSONSerializable extends ConfigurationSerializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize this object into a JSON string.
|
||||||
|
*
|
||||||
|
* @return JSON string contains serialized data.
|
||||||
|
*/
|
||||||
|
default @NotNull String serializeToJSON() {
|
||||||
|
return BukkitJSONSerializer.get().serializeToJSON(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import cc.carm.lib.bukkit.configuration.BukkitJSONSerializer;
|
||||||
|
import cc.carm.lib.bukkit.configuration.JSONSerializable;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class demo {
|
||||||
|
|
||||||
|
public static void demoUsage() {
|
||||||
|
BukkitJSONSerializer serializer = BukkitJSONSerializer.create();
|
||||||
|
|
||||||
|
Location location = new Location(Bukkit.getWorlds().get(0), -100.5, 100, 105.5);
|
||||||
|
|
||||||
|
String serialized = serializer.serializeToJSON(location);
|
||||||
|
// serialized -> {"world":"world","x":-100.5,"y":100,"z":105.5,"yaw":0.0,"pitch":0.0}
|
||||||
|
|
||||||
|
Location deserialized = serializer.deserializeJSON(serialized, Location.class);
|
||||||
|
// deserialized -> Location{world=world, x=-100.5, y=100, z=105.5, pitch=0.0, yaw=0.0}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class SomeValue implements JSONSerializable {
|
||||||
|
|
||||||
|
long time;
|
||||||
|
UUID uuid;
|
||||||
|
|
||||||
|
public SomeValue(long time, UUID uuid) {
|
||||||
|
this.time = time;
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("time", time);
|
||||||
|
map.put("uuid", uuid.toString());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SomeValue deserialize(Map<String, Object> map) {
|
||||||
|
return new SomeValue(
|
||||||
|
(long) map.get("time"),
|
||||||
|
UUID.fromString((String) map.get("uuid"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user