mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2024-09-19 20:05:49 +00:00
[1.0.0] 初始版本完成
This commit is contained in:
parent
1bcc8d832e
commit
589de2606c
178
LICENSE
178
LICENSE
@ -1,21 +1,165 @@
|
|||||||
MIT License
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
Copyright (c) 2022 Carm
|
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.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
This version of the GNU Lesser General Public License incorporates
|
||||||
copies or substantial portions of the Software.
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
0. Additional Definitions.
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
General Public License.
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
"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.
|
153
README.md
153
README.md
@ -18,6 +18,138 @@ EasyConfiguration for MineCraft!
|
|||||||
|
|
||||||
开始在 MineCraft 相关服务器平台上**轻松(做)配置**吧!
|
开始在 MineCraft 相关服务器平台上**轻松(做)配置**吧!
|
||||||
|
|
||||||
|
## 开发
|
||||||
|
|
||||||
|
### 项目结构
|
||||||
|
|
||||||
|
#### MineConfiguration-CraftBukkit
|
||||||
|
|
||||||
|
CraftBukkit系通用依赖,不包含实现部分,请使用 MineConfiguration-Bukkit 或 MineConfiguration-Spigot 。
|
||||||
|
|
||||||
|
#### MineConfiguration-Bukkit
|
||||||
|
|
||||||
|
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端*(如Spigot、Paper、CatServer)*。
|
||||||
|
|
||||||
|
#### MineConfiguration-Spigot
|
||||||
|
|
||||||
|
适用于 Spigot(1.18+) 的版本,适配了1.18与更新版本自带的配置文件注释功能,更加稳定。
|
||||||
|
|
||||||
|
#### MineConfiguration-Bungee
|
||||||
|
|
||||||
|
适用于BungeeCord的版本,可用JSON与YAML格式,但**不支持配置文件注释**。
|
||||||
|
如需使用配置文件注释,建议使用 [EasyConfiguration-YAML](https://github.com/CarmJos/EasyConfiguration) 。
|
||||||
|
|
||||||
|
### 依赖方式
|
||||||
|
|
||||||
|
#### Maven 依赖
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>远程库配置</summary>
|
||||||
|
|
||||||
|
```xml
|
||||||
|
|
||||||
|
<project>
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--采用Maven中心库,安全稳定,但版本更新需要等待同步-->
|
||||||
|
<id>maven</id>
|
||||||
|
<name>Maven Central</name>
|
||||||
|
<url>https://repo1.maven.org/maven2</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--采用github依赖库,实时更新,但需要配置 (推荐) -->
|
||||||
|
<id>EasyConfiguration</id>
|
||||||
|
<name>GitHub Packages</name>
|
||||||
|
<url>https://maven.pkg.github.com/CarmJos/MineConfiguration</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||||
|
<id>carm-repo</id>
|
||||||
|
<name>Carm's Repo</name>
|
||||||
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>通用原生依赖</summary>
|
||||||
|
|
||||||
|
```xml
|
||||||
|
|
||||||
|
<project>
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||||
|
<version>[LATEST RELEASE]</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>mineconfiguration-spigot</artifactId>
|
||||||
|
<version>[LATEST RELEASE]</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>mineconfiguration-bungee</artifactId>
|
||||||
|
<version>[LATEST RELEASE]</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
#### Gradle 依赖
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>远程库配置</summary>
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
repositories {
|
||||||
|
|
||||||
|
// 采用Maven中心库,安全稳定,但版本更新需要等待同步
|
||||||
|
mavenCentral()
|
||||||
|
|
||||||
|
// 采用github依赖库,实时更新,但需要配置 (推荐)
|
||||||
|
maven { url 'https://maven.pkg.github.com/CarmJos/MineConfiguration' }
|
||||||
|
|
||||||
|
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||||
|
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>通用原生依赖</summary>
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
api "cc.carm.lib:mineconfiguration-bukkit:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
api "cc.carm.lib:mineconfiguration-spigot:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
api "cc.carm.lib:mineconfiguration-bungee:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 支持与捐赠
|
## 支持与捐赠
|
||||||
|
|
||||||
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
||||||
@ -28,23 +160,4 @@ EasyConfiguration for MineCraft!
|
|||||||
|
|
||||||
## 开源协议
|
## 开源协议
|
||||||
|
|
||||||
本项目源码采用 [The MIT License](https://opensource.org/licenses/MIT) 开源协议。
|
本项目源码采用 [GNU LESSER GENERAL PUBLIC LICENSE](https://www.gnu.org/licenses/lgpl-3.0.html) 开源协议。
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>关于 MIT 协议</summary>
|
|
||||||
|
|
||||||
> MIT 协议可能是几大开源协议中最宽松的一个,核心条款是:
|
|
||||||
>
|
|
||||||
> 该软件及其相关文档对所有人免费,可以任意处置,包括使用,复制,修改,合并,发表,分发,再授权,或者销售。唯一的限制是,软件中必须包含上述版 权和许可提示。
|
|
||||||
>
|
|
||||||
> 这意味着:
|
|
||||||
>
|
|
||||||
> - 你可以自由使用,复制,修改,可以用于自己的项目。
|
|
||||||
> - 可以免费分发或用来盈利。
|
|
||||||
> - 唯一的限制是必须包含许可声明。
|
|
||||||
>
|
|
||||||
> MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。
|
|
||||||
>
|
|
||||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.builder.BukkitConfigBuilder;
|
|
||||||
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
|
||||||
import cc.carm.lib.configuration.bukkit.source.BukkitSectionWrapper;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public abstract class BukkitConfigValue<T> extends CachedConfigValue<T> {
|
|
||||||
|
|
||||||
public static @NotNull BukkitConfigBuilder builder() {
|
|
||||||
return new BukkitConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public BukkitConfigValue(@Nullable BukkitConfigProvider provider,
|
|
||||||
@Nullable String configPath, @NotNull String[] comments, @Nullable T defaultValue) {
|
|
||||||
super(provider, configPath, comments, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitConfigProvider<?, ?> getBukkitProvider() {
|
|
||||||
ConfigurationProvider<?> provider = getProvider();
|
|
||||||
if (provider instanceof BukkitConfigProvider) return (BukkitConfigProvider<?, ?>) getProvider();
|
|
||||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitSectionWrapper getBukkitConfig() {
|
|
||||||
return getBukkitProvider().getConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.builder;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
|
||||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
|
||||||
|
|
||||||
public abstract class AbstractBukkitBuilder<T, B extends AbstractBukkitBuilder<T, B>>
|
|
||||||
extends AbstractConfigBuilder<T, B, BukkitConfigProvider<?, ?>> {
|
|
||||||
|
|
||||||
public AbstractBukkitBuilder() {
|
|
||||||
super(BukkitConfigProvider.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,73 +0,0 @@
|
|||||||
//package cc.carm.lib.configuration.bukkit.commented;
|
|
||||||
//
|
|
||||||
//import org.yaml.snakeyaml.DumperOptions;
|
|
||||||
//import org.yaml.snakeyaml.Yaml;
|
|
||||||
//import org.yaml.snakeyaml.constructor.BaseConstructor;
|
|
||||||
//import org.yaml.snakeyaml.error.YAMLException;
|
|
||||||
//import org.yaml.snakeyaml.nodes.Node;
|
|
||||||
//import org.yaml.snakeyaml.nodes.Tag;
|
|
||||||
//import org.yaml.snakeyaml.representer.Representer;
|
|
||||||
//import org.yaml.snakeyaml.serializer.Serializer;
|
|
||||||
//
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import java.io.StringWriter;
|
|
||||||
//import java.io.Writer;
|
|
||||||
//import java.util.ArrayList;
|
|
||||||
//import java.util.Iterator;
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * A hacky extension of {@link Yaml} that allows to write comments when dumping.
|
|
||||||
// */
|
|
||||||
//public class CommentedYaml extends Yaml {
|
|
||||||
//
|
|
||||||
// private final CommentsProvider commentsProvider;
|
|
||||||
//
|
|
||||||
// public CommentedYaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions, CommentsProvider commentsProvider) {
|
|
||||||
// super(constructor, representer, dumperOptions);
|
|
||||||
// this.commentsProvider = commentsProvider;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String dump(Object data) {
|
|
||||||
// List<Object> list = new ArrayList<>(1);
|
|
||||||
// list.add(data);
|
|
||||||
// return this.dumpAll(list.iterator());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void dump(Object data, Writer output) {
|
|
||||||
// List<Object> list = new ArrayList<>(1);
|
|
||||||
// list.add(data);
|
|
||||||
// this.dumpAll(list.iterator(), output, null);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String dumpAll(Iterator<?> data) {
|
|
||||||
// StringWriter buffer = new StringWriter();
|
|
||||||
// this.dumpAll(data, buffer, null);
|
|
||||||
// return buffer.toString();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void dumpAll(Iterator<?> data, Writer output) {
|
|
||||||
// this.dumpAll(data, output, null);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void dumpAll(Iterator<?> data, Writer output, Tag rootTag) {
|
|
||||||
// Serializer serializer = new Serializer(new CommentedEmitter(output, this.dumperOptions, this.commentsProvider), this.resolver, this.dumperOptions, rootTag);
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// serializer.open();
|
|
||||||
//
|
|
||||||
// while (data.hasNext()) {
|
|
||||||
// Node node = this.representer.represent(data.next());
|
|
||||||
// serializer.serialize(node);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// serializer.close();
|
|
||||||
// } catch (IOException var6) {
|
|
||||||
// throw new YAMLException(var6);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -1,69 +0,0 @@
|
|||||||
//package cc.carm.lib.configuration.bukkit.commented;
|
|
||||||
//
|
|
||||||
//import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
//import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
//import org.bukkit.configuration.file.YamlConstructor;
|
|
||||||
//import org.bukkit.configuration.file.YamlRepresenter;
|
|
||||||
//import org.jetbrains.annotations.NotNull;
|
|
||||||
//import org.yaml.snakeyaml.DumperOptions;
|
|
||||||
//import org.yaml.snakeyaml.representer.Representer;
|
|
||||||
//
|
|
||||||
//import java.io.File;
|
|
||||||
//import java.io.FileNotFoundException;
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import java.io.Reader;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * A yaml file with comments on certain properties, as returned by the given {@link CommentsProvider}.
|
|
||||||
// * Unlike {@link YamlConfiguration}, this class does not provide a header support.
|
|
||||||
// */
|
|
||||||
//public class CommentedYamlConfiguration extends YamlConfiguration {
|
|
||||||
//
|
|
||||||
// private final DumperOptions yamlOptions = new DumperOptions();
|
|
||||||
// private final Representer yamlRepresenter = new YamlRepresenter();
|
|
||||||
// private final CommentedYaml yaml;
|
|
||||||
//
|
|
||||||
// public CommentedYamlConfiguration(CommentsProvider commentsProvider) {
|
|
||||||
// this.yaml = new CommentedYaml(new YamlConstructor(), this.yamlRepresenter, this.yamlOptions, commentsProvider);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static CommentedYamlConfiguration loadConfiguration(CommentsProvider commentsProvider, File file) {
|
|
||||||
// CommentedYamlConfiguration config = new CommentedYamlConfiguration(commentsProvider);
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// config.load(file);
|
|
||||||
// } catch (FileNotFoundException ignored) {
|
|
||||||
// } catch (IOException | InvalidConfigurationException var4) {
|
|
||||||
// var4.printStackTrace();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return config;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static CommentedYamlConfiguration loadConfiguration(CommentsProvider commentsProvider, Reader reader) {
|
|
||||||
// CommentedYamlConfiguration config = new CommentedYamlConfiguration(commentsProvider);
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// config.load(reader);
|
|
||||||
// } catch (IOException | InvalidConfigurationException ex) {
|
|
||||||
// ex.printStackTrace();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return config;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public @NotNull String saveToString() {
|
|
||||||
// this.yamlOptions.setIndent(this.options().indent());
|
|
||||||
// this.yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
|
||||||
// this.yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
|
||||||
// String dump = this.yaml.dump(this.getValues(false));
|
|
||||||
// if (dump.equals("{}\n")) {
|
|
||||||
// dump = "";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // No header support.
|
|
||||||
//
|
|
||||||
// return dump;
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -1,7 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.commented;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
|
|
||||||
public interface CommentsProvider extends Function<String, String[]> {
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.commented;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ConfigComments implements CommentsProvider {
|
|
||||||
|
|
||||||
Map<String, String[]> comments = new HashMap<>();
|
|
||||||
|
|
||||||
protected Map<String, String[]> getComments() {
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(@NotNull String path, @NotNull String... comments) {
|
|
||||||
if (comments.length == 0) {
|
|
||||||
getComments().remove(path);
|
|
||||||
} else {
|
|
||||||
getComments().put(path, comments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable String[] get(@NotNull String path) {
|
|
||||||
return getComments().get(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] apply(String s) {
|
|
||||||
return get(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.data;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ItemConfig {
|
|
||||||
|
|
||||||
@NotNull Material type;
|
|
||||||
@Nullable String name;
|
|
||||||
@Nullable List<String> lore;
|
|
||||||
@NotNull Map<String, List<String>> additional;
|
|
||||||
|
|
||||||
public ItemConfig(@NotNull Material type, @Nullable String name,
|
|
||||||
@Nullable List<String> lore, @NotNull Map<String, List<String>> additional) {
|
|
||||||
this.type = type;
|
|
||||||
this.name = name;
|
|
||||||
this.lore = lore;
|
|
||||||
this.additional = additional;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull Material getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable List<String> getLore() {
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull Map<String, List<String>> getAdditionalLore() {
|
|
||||||
return additional;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.data;
|
|
||||||
|
|
||||||
public class MessageConfig {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
public abstract class BukkitSectionWrapper implements ConfigurationWrapper {
|
|
||||||
|
|
||||||
private final ConfigurationSection section;
|
|
||||||
|
|
||||||
private BukkitSectionWrapper(ConfigurationSection section) {
|
|
||||||
this.section = section;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigurationSection getSourceSection() {
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.value;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.data.ItemConfig;
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
|
||||||
|
|
||||||
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider,
|
|
||||||
@Nullable String sectionPath, @NotNull String[] comments,
|
|
||||||
@NotNull Class<ItemConfig> valueClass, @Nullable ItemConfig defaultValue,
|
|
||||||
@NotNull ConfigValueParser<ConfigurationWrapper, ItemConfig> parser,
|
|
||||||
@NotNull ConfigDataFunction<ItemConfig, ? extends Map<String, Object>> serializer) {
|
|
||||||
super(provider, sectionPath, comments, valueClass, defaultValue, parser, serializer);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.value;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.data.MessageConfig;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class ConfiguredMessage extends CachedConfigValue<MessageConfig> {
|
|
||||||
|
|
||||||
|
|
||||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
|
|
||||||
@Nullable String sectionPath, @NotNull String[] comments,
|
|
||||||
@Nullable MessageConfig defaultValue) {
|
|
||||||
super(provider, sectionPath, comments, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable MessageConfig get() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(@Nullable MessageConfig value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
64
bukkit/pom.xml
Normal file
64
bukkit/pom.xml
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyconfiguration-core</artifactId>
|
||||||
|
<version>${easyconfiguration.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.lib.configuration;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class MineConfiguration {
|
||||||
|
|
||||||
|
public static BukkitConfigProvider from(File file, String source) {
|
||||||
|
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
||||||
|
try {
|
||||||
|
provider.initializeFile(source);
|
||||||
|
provider.initializeConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitConfigProvider from(File file) {
|
||||||
|
return from(file, file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitConfigProvider from(String fileName) {
|
||||||
|
return from(fileName, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitConfigProvider from(String fileName, String source) {
|
||||||
|
return from(new File(fileName), source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package cc.carm.lib.configuration.bukkit.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||||
|
import cc.carm.lib.configuration.craft.source.CraftSectionWrapper;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class BukkitConfigProvider extends CraftConfigProvider {
|
||||||
|
|
||||||
|
protected static final char SEPARATOR = '.';
|
||||||
|
|
||||||
|
protected BukkitYAMLComments bukkitComments = new BukkitYAMLComments();
|
||||||
|
|
||||||
|
public BukkitConfigProvider(@NotNull File file) {
|
||||||
|
super(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeConfig() {
|
||||||
|
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||||
|
this.initializer = new ConfigInitializer<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull CraftSectionWrapper getConfiguration() {
|
||||||
|
return CraftSectionWrapper.of(this.configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() throws Exception {
|
||||||
|
configuration.load(getFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() throws Exception {
|
||||||
|
configuration.save(getFile());
|
||||||
|
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
this.bukkitComments.writeComments(configuration, new BufferedWriter(writer));
|
||||||
|
String value = writer.toString(); // config contents
|
||||||
|
|
||||||
|
Path toUpdatePath = getFile().toPath();
|
||||||
|
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
||||||
|
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
||||||
|
this.bukkitComments.set(path, comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
||||||
|
return this.bukkitComments.get(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
package cc.carm.lib.configuration.bukkit.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import static cc.carm.lib.configuration.craft.source.CraftConfigProvider.SEPARATOR;
|
||||||
|
|
||||||
|
public class BukkitYAMLComments {
|
||||||
|
|
||||||
|
Map<String, ConfigCommentInfo> comments = new HashMap<>();
|
||||||
|
|
||||||
|
protected Map<String, ConfigCommentInfo> getComments() {
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@Nullable String path, @Nullable ConfigCommentInfo comments) {
|
||||||
|
if (comments == null) {
|
||||||
|
getComments().remove(path);
|
||||||
|
} else {
|
||||||
|
getComments().put(path, comments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ConfigCommentInfo get(@Nullable String path) {
|
||||||
|
return getComments().getOrDefault(path, ConfigCommentInfo.defaults());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String buildComments(@NotNull String indents, @Nullable String path) {
|
||||||
|
ConfigCommentInfo comments = get(path);
|
||||||
|
if (!String.join("", comments.getComments()).isEmpty()) {
|
||||||
|
String prefix = comments.startWrap() ? "\n" : "";
|
||||||
|
String suffix = comments.endWrap() ? "\n" : "";
|
||||||
|
StringJoiner joiner = new StringJoiner("\n", prefix, suffix);
|
||||||
|
for (String comment : comments.getComments()) {
|
||||||
|
if (comment.length() == 0) joiner.add(" ");
|
||||||
|
else joiner.add(indents + "# " + comment);
|
||||||
|
}
|
||||||
|
return joiner + "\n";
|
||||||
|
} else {
|
||||||
|
return comments.startWrap() || comments.endWrap() ? "\n" : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从一个文件读取配置并写入注释到某个写入器中。
|
||||||
|
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
||||||
|
*
|
||||||
|
* @param source 源配置文件
|
||||||
|
* @param writer 配置写入器
|
||||||
|
* @throws IOException 当写入发生错误时抛出
|
||||||
|
*/
|
||||||
|
public void writeComments(@NotNull YamlConfiguration source, @NotNull BufferedWriter writer) throws IOException {
|
||||||
|
FileConfiguration temp = new YamlConfiguration(); // 该对象用于临时记录配置内容
|
||||||
|
|
||||||
|
for (String fullKey : source.getKeys(true)) {
|
||||||
|
String indents = getIndents(fullKey);
|
||||||
|
String comment = buildComments(indents, fullKey);
|
||||||
|
if (comment != null) writer.write(comment);
|
||||||
|
|
||||||
|
Object currentValue = source.get(fullKey);
|
||||||
|
|
||||||
|
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
||||||
|
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
||||||
|
|
||||||
|
if (currentValue instanceof ConfigurationSection) {
|
||||||
|
writer.write(indents + trailingKey + ":");
|
||||||
|
if (!((ConfigurationSection) currentValue).getKeys(false).isEmpty()) {
|
||||||
|
writer.write("\n");
|
||||||
|
} else {
|
||||||
|
writer.write(" {}\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp.set(trailingKey, currentValue);
|
||||||
|
String yaml = temp.saveToString();
|
||||||
|
yaml = yaml.substring(0, yaml.length() - 1).replace("\n", "\n" + indents);
|
||||||
|
String toWrite = indents + yaml + "\n";
|
||||||
|
temp.set(trailingKey, null);
|
||||||
|
|
||||||
|
writer.write(toWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
String endComment = buildComments("", null);
|
||||||
|
if (endComment != null) writer.write(endComment);
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到一个键的缩进。
|
||||||
|
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @return 该键的缩进文本
|
||||||
|
*/
|
||||||
|
protected static String getIndents(String key) {
|
||||||
|
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
||||||
|
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>MineConfiguration</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cc.carm.lib.configuration.bungee;
|
package cc.carm.lib.configuration.bungee;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
@ -42,14 +43,13 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setComments(@NotNull String path, @NotNull String... comments) {
|
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
||||||
// BungeeCord version doesn't support comments
|
// BungeeCord version doesn't support comments
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String[] getComments(@NotNull String path) {
|
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
||||||
// BungeeCord version doesn't support comments
|
return null; // BungeeCord version doesn't support comments
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,17 +3,16 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>MineConfiguration</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>mineconfiguration-bukkit-common</artifactId>
|
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -26,8 +25,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.lib.configuration.craft;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.craft.builder.CraftConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||||
|
import cc.carm.lib.configuration.craft.source.CraftSectionWrapper;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
|
public static @NotNull CraftConfigBuilder builder() {
|
||||||
|
return new CraftConfigBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftConfigValue(@Nullable CraftConfigProvider provider,
|
||||||
|
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
|
||||||
|
super(provider, configPath, comments, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftConfigProvider getBukkitProvider() {
|
||||||
|
ConfigurationProvider<?> provider = getProvider();
|
||||||
|
if (provider instanceof CraftConfigProvider) return (CraftConfigProvider) getProvider();
|
||||||
|
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftSectionWrapper getBukkitConfig() {
|
||||||
|
return getBukkitProvider().getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.builder;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||||
|
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||||
|
|
||||||
|
public abstract class AbstractCraftBuilder<T, B extends AbstractCraftBuilder<T, B>>
|
||||||
|
extends AbstractConfigBuilder<T, B, CraftConfigProvider> {
|
||||||
|
|
||||||
|
public AbstractCraftBuilder() {
|
||||||
|
super(CraftConfigProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.builder;
|
package cc.carm.lib.configuration.craft.builder;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.builder.serializable.SerializableBuilder;
|
import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder;
|
||||||
import cc.carm.lib.configuration.bukkit.builder.sound.SoundConfigBuilder;
|
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
||||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BukkitConfigBuilder extends ConfigBuilder {
|
public class CraftConfigBuilder extends ConfigBuilder {
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder createSound() {
|
public @NotNull SoundConfigBuilder createSound() {
|
||||||
return new SoundConfigBuilder();
|
return new SoundConfigBuilder();
|
@ -1,12 +1,12 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.builder.serializable;
|
package cc.carm.lib.configuration.craft.builder.serializable;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.builder.AbstractBukkitBuilder;
|
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
||||||
import cc.carm.lib.configuration.bukkit.value.ConfiguredSerializable;
|
import cc.carm.lib.configuration.craft.value.ConfiguredSerializable;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class SerializableBuilder<T extends ConfigurationSerializable>
|
public class SerializableBuilder<T extends ConfigurationSerializable>
|
||||||
extends AbstractBukkitBuilder<T, SerializableBuilder<T>> {
|
extends AbstractCraftBuilder<T, SerializableBuilder<T>> {
|
||||||
|
|
||||||
protected final @NotNull Class<T> valueClass;
|
protected final @NotNull Class<T> valueClass;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredSerializable<T> build() {
|
public @NotNull ConfiguredSerializable<T> build() {
|
||||||
return new ConfiguredSerializable<>(this.provider, this.path, this.comments, this.valueClass, this.defaultValue);
|
return new ConfiguredSerializable<>(this.provider, this.path, buildComments(), this.valueClass, this.defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.builder.sound;
|
package cc.carm.lib.configuration.craft.builder.sound;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.builder.AbstractBukkitBuilder;
|
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
||||||
import cc.carm.lib.configuration.bukkit.data.SoundConfig;
|
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
||||||
import cc.carm.lib.configuration.bukkit.value.ConfiguredSound;
|
import cc.carm.lib.configuration.craft.value.ConfiguredSound;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class SoundConfigBuilder extends AbstractBukkitBuilder<SoundConfig, SoundConfigBuilder> {
|
public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundConfigBuilder> {
|
||||||
|
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume, float pitch) {
|
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume, float pitch) {
|
||||||
@ -28,7 +28,7 @@ public class SoundConfigBuilder extends AbstractBukkitBuilder<SoundConfig, Sound
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredSound build() {
|
public @NotNull ConfiguredSound build() {
|
||||||
return new ConfiguredSound(this.provider, this.path, this.comments, this.defaultValue);
|
return new ConfiguredSound(this.provider, this.path, buildComments(), this.defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ItemConfig {
|
||||||
|
|
||||||
|
@NotNull Material type;
|
||||||
|
short data;
|
||||||
|
@Nullable String name;
|
||||||
|
@NotNull List<String> lore;
|
||||||
|
@NotNull Map<String, List<String>> additional;
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, short damage,
|
||||||
|
@Nullable String name, @NotNull List<String> lore,
|
||||||
|
@NotNull Map<String, List<String>> additional) {
|
||||||
|
this.type = type;
|
||||||
|
this.data = damage;
|
||||||
|
this.name = name;
|
||||||
|
this.lore = lore;
|
||||||
|
this.additional = additional;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Material getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> getLore() {
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, List<String>> getAdditionalLore() {
|
||||||
|
return additional;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack() {
|
||||||
|
return getItemStack(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(int amount, @NotNull String... withAdditional) {
|
||||||
|
ItemStack item = new ItemStack(type, amount, data);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return item;
|
||||||
|
|
||||||
|
if (getName() != null) meta.setDisplayName(getName());
|
||||||
|
|
||||||
|
List<String> finalLore = new ArrayList<>();
|
||||||
|
if (!this.lore.isEmpty()) finalLore.addAll(this.lore);
|
||||||
|
|
||||||
|
for (String s : withAdditional) {
|
||||||
|
List<String> additional = this.additional.get(s);
|
||||||
|
if (additional != null) finalLore.addAll(additional);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!finalLore.isEmpty()) meta.setLore(finalLore);
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @NotNull Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("type", type.name());
|
||||||
|
if (this.data != 0) map.put("data", data);
|
||||||
|
if (name != null) map.put("name", name);
|
||||||
|
if (!lore.isEmpty()) map.put("lore", lore);
|
||||||
|
if (!additional.isEmpty()) map.put("additional", additional);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
|
||||||
|
String typeName = section.getString("name");
|
||||||
|
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||||
|
|
||||||
|
Material type = Material.matchMaterial(typeName);
|
||||||
|
if (type == null) throw new Exception("Invalid material name: " + typeName);
|
||||||
|
else return new ItemConfig(
|
||||||
|
type, section.getShort("data", (short) 0), section.getString("name"),
|
||||||
|
parseStringList(section.getList("lore")),
|
||||||
|
readAdditionalLore(section.getConfigurationSection("additional"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> parseStringList(@Nullable List<?> data) {
|
||||||
|
if (data == null) return new ArrayList<>();
|
||||||
|
else return data.stream()
|
||||||
|
.map(o -> o instanceof String ? (String) o : o.toString())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, List<String>> readAdditionalLore(@Nullable ConfigurationWrapper loreSection) {
|
||||||
|
Map<String, List<String>> additionalMap = new HashMap<>();
|
||||||
|
if (loreSection == null) return additionalMap;
|
||||||
|
|
||||||
|
for (String loreName : loreSection.getKeys(false)) {
|
||||||
|
if (!loreSection.isList(loreName)) continue;
|
||||||
|
|
||||||
|
List<String> additionalLore = parseStringList(loreSection.getList(loreName));
|
||||||
|
if (additionalLore.isEmpty()) continue;
|
||||||
|
|
||||||
|
additionalMap.put(loreName, additionalLore);
|
||||||
|
}
|
||||||
|
|
||||||
|
return additionalMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.data;
|
package cc.carm.lib.configuration.craft.data;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -9,19 +9,19 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class SoundConfig {
|
public class SoundConfig {
|
||||||
|
|
||||||
protected Sound type;
|
protected @NotNull Sound type;
|
||||||
protected float volume;
|
protected float volume;
|
||||||
protected float pitch;
|
protected float pitch;
|
||||||
|
|
||||||
public SoundConfig(Sound type) {
|
public SoundConfig(@NotNull Sound type) {
|
||||||
this(type, 1, 1);
|
this(type, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundConfig(Sound type, float volume) {
|
public SoundConfig(@NotNull Sound type, float volume) {
|
||||||
this(type, volume, 1);
|
this(type, volume, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundConfig(Sound type, float volume, float pitch) {
|
public SoundConfig(@NotNull Sound type, float volume, float pitch) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.volume = volume;
|
this.volume = volume;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
@ -35,6 +35,30 @@ public class SoundConfig {
|
|||||||
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull Sound getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPitch() {
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getVolume() {
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(@NotNull Sound type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVolume(float volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull String serialize() {
|
public @NotNull String serialize() {
|
||||||
if (pitch != 1) {
|
if (pitch != 1) {
|
||||||
return type.name() + ":" + volume + ":" + pitch;
|
return type.name() + ":" + volume + ":" + pitch;
|
@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.source;
|
package cc.carm.lib.configuration.craft.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||||
@ -7,20 +7,23 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public abstract class BukkitConfigProvider<W extends BukkitSectionWrapper, C extends YamlConfiguration>
|
public abstract class CraftConfigProvider extends FileConfigProvider<CraftSectionWrapper> {
|
||||||
extends FileConfigProvider<W> {
|
|
||||||
|
|
||||||
protected ConfigInitializer<? extends BukkitConfigProvider<W, C>> initializer;
|
public static final char SEPARATOR = '.';
|
||||||
protected C configuration;
|
|
||||||
|
|
||||||
public BukkitConfigProvider(@NotNull File file) {
|
protected ConfigInitializer<? extends CraftConfigProvider> initializer;
|
||||||
|
protected YamlConfiguration configuration;
|
||||||
|
|
||||||
|
public CraftConfigProvider(@NotNull File file) {
|
||||||
super(file);
|
super(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void initializeConfig();
|
public abstract void initializeConfig();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract @NotNull W getConfiguration();
|
public @NotNull CraftSectionWrapper getConfiguration() {
|
||||||
|
return CraftSectionWrapper.of(this.configuration);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() throws Exception {
|
public void reload() throws Exception {
|
||||||
@ -33,7 +36,7 @@ public abstract class BukkitConfigProvider<W extends BukkitSectionWrapper, C ext
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfigInitializer<? extends BukkitConfigProvider<W, C>> getInitializer() {
|
public @NotNull ConfigInitializer<? extends CraftConfigProvider> getInitializer() {
|
||||||
return this.initializer;
|
return this.initializer;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class CraftSectionWrapper implements ConfigurationWrapper {
|
||||||
|
|
||||||
|
protected final ConfigurationSection section;
|
||||||
|
|
||||||
|
protected CraftSectionWrapper(ConfigurationSection section) {
|
||||||
|
this.section = section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationSection getSourceSection() {
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Set<String> getKeys(boolean deep) {
|
||||||
|
return this.section.getKeys(deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||||
|
return this.section.getValues(deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(@NotNull String path, @Nullable Object value) {
|
||||||
|
this.section.set(path, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(@NotNull String path) {
|
||||||
|
return this.section.contains(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Object get(@NotNull String path) {
|
||||||
|
return this.section.get(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isList(@NotNull String path) {
|
||||||
|
return this.section.isList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<?> getList(@NotNull String path) {
|
||||||
|
return this.section.getList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConfigurationSection(@NotNull String path) {
|
||||||
|
return this.section.isConfigurationSection(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
||||||
|
return Optional.ofNullable(section.getConfigurationSection(path))
|
||||||
|
.map(CraftSectionWrapper::of).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftSectionWrapper of(ConfigurationSection section) {
|
||||||
|
return new CraftSectionWrapper(section);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package cc.carm.lib.configuration.craft.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
|
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
||||||
|
|
||||||
|
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider,
|
||||||
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
|
@Nullable ItemConfig defaultValue) {
|
||||||
|
super(provider, sectionPath, comments, ItemConfig.class, defaultValue, getItemParser(), ItemConfig::serialize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigValueParser<ConfigurationWrapper, ItemConfig> getItemParser() {
|
||||||
|
return (s, d) -> ItemConfig.deserialize(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,15 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.value;
|
package cc.carm.lib.configuration.craft.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.BukkitConfigValue;
|
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||||
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends BukkitConfigValue<T> {
|
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
||||||
|
|
||||||
public static <V extends ConfigurationSerializable> ConfiguredSerializable<V> of(@NotNull Class<V> valueClass) {
|
public static <V extends ConfigurationSerializable> ConfiguredSerializable<V> of(@NotNull Class<V> valueClass) {
|
||||||
return of(valueClass, null);
|
return of(valueClass, null);
|
||||||
@ -21,8 +22,8 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
|||||||
|
|
||||||
protected final @NotNull Class<T> valueClass;
|
protected final @NotNull Class<T> valueClass;
|
||||||
|
|
||||||
public ConfiguredSerializable(@Nullable BukkitConfigProvider provider,
|
public ConfiguredSerializable(@Nullable CraftConfigProvider provider,
|
||||||
@Nullable String configPath, @NotNull String[] comments,
|
@Nullable String configPath, @Nullable ConfigCommentInfo comments,
|
||||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
||||||
super(provider, configPath, comments, defaultValue);
|
super(provider, configPath, comments, defaultValue);
|
||||||
this.valueClass = valueClass;
|
this.valueClass = valueClass;
|
@ -1,10 +1,11 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.value;
|
package cc.carm.lib.configuration.craft.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.BukkitConfigValue;
|
|
||||||
import cc.carm.lib.configuration.bukkit.data.SoundConfig;
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
|
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||||
|
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -15,24 +16,35 @@ import java.util.Optional;
|
|||||||
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||||
|
|
||||||
public static @NotNull ConfiguredSound of(Sound sound) {
|
public static @NotNull ConfiguredSound of(Sound sound) {
|
||||||
return BukkitConfigValue.builder().createSound().defaults(sound).build();
|
return CraftConfigValue.builder().createSound().defaults(sound).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull ConfiguredSound of(Sound sound, float volume) {
|
public static @NotNull ConfiguredSound of(Sound sound, float volume) {
|
||||||
return BukkitConfigValue.builder().createSound().defaults(sound, volume).build();
|
return CraftConfigValue.builder().createSound().defaults(sound, volume).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull ConfiguredSound of(Sound sound, float volume, float pitch) {
|
public static @NotNull ConfiguredSound of(Sound sound, float volume, float pitch) {
|
||||||
return BukkitConfigValue.builder().createSound().defaults(sound, volume, pitch).build();
|
return CraftConfigValue.builder().createSound().defaults(sound, volume, pitch).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider,
|
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider,
|
||||||
@Nullable String sectionPath, @NotNull String[] comments,
|
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||||
@Nullable SoundConfig defaultValue) {
|
@Nullable SoundConfig defaultValue) {
|
||||||
super(provider, sectionPath, comments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
super(provider, sectionPath, comments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSound(@NotNull Sound sound) {
|
||||||
|
setSound(sound, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSound(@NotNull Sound sound, float volume) {
|
||||||
|
setSound(sound, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSound(@NotNull Sound sound, float volume, float pitch) {
|
||||||
|
set(new SoundConfig(sound, volume, pitch));
|
||||||
|
}
|
||||||
|
|
||||||
public void playTo(@NotNull Player player) {
|
public void playTo(@NotNull Player player) {
|
||||||
Optional.ofNullable(get()).ifPresent(c -> c.playTo(player));
|
Optional.ofNullable(get()).ifPresent(c -> c.playTo(player));
|
||||||
}
|
}
|
9
pom.xml
9
pom.xml
@ -5,7 +5,10 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<modules>
|
<modules>
|
||||||
<module>bungee</module>
|
<module>bungee</module>
|
||||||
<module>bukkit/common</module>
|
|
||||||
|
<module>craftbukkit</module>
|
||||||
|
<module>bukkit</module>
|
||||||
|
<module>spigot</module>
|
||||||
</modules>
|
</modules>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
@ -14,10 +17,10 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
<easyconfiguration.version>1.1.0</easyconfiguration.version>
|
<easyconfiguration.version>2.3.0</easyconfiguration.version>
|
||||||
</properties>
|
</properties>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>MineConfiguration</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
65
spigot/pom.xml
Normal file
65
spigot/pom.xml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<artifactId>minecronfiguration-spigot</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyconfiguration-core</artifactId>
|
||||||
|
<version>${easyconfiguration.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.lib.configuration;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.spigot.source.SpigotConfigProvider;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class MineConfiguration {
|
||||||
|
|
||||||
|
public static SpigotConfigProvider from(File file, String source) {
|
||||||
|
SpigotConfigProvider provider = new SpigotConfigProvider(file);
|
||||||
|
try {
|
||||||
|
provider.initializeFile(source);
|
||||||
|
provider.initializeConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpigotConfigProvider from(File file) {
|
||||||
|
return from(file, file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpigotConfigProvider from(String fileName) {
|
||||||
|
return from(fileName, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpigotConfigProvider from(String fileName, String source) {
|
||||||
|
return from(new File(fileName), source);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package cc.carm.lib.configuration.spigot.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||||
|
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SpigotConfigProvider extends CraftConfigProvider {
|
||||||
|
|
||||||
|
public SpigotConfigProvider(@NotNull File file) {
|
||||||
|
super(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeConfig() {
|
||||||
|
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||||
|
this.initializer = new ConfigInitializer<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo commentInfo) {
|
||||||
|
if (path == null) {
|
||||||
|
if (commentInfo == null) this.configuration.options().setFooter(null);
|
||||||
|
else if (!String.join("", commentInfo.getComments()).isEmpty()) {
|
||||||
|
this.configuration.options().setFooter(Arrays.asList(commentInfo.getComments()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (commentInfo == null) this.configuration.setComments(path, null);
|
||||||
|
else {
|
||||||
|
List<String> comments = new ArrayList<>();
|
||||||
|
|
||||||
|
if (!String.join("", commentInfo.getComments()).isEmpty()) {
|
||||||
|
if (commentInfo.startWrap()) comments.add("");
|
||||||
|
comments.addAll(Arrays.asList(commentInfo.getComments()));
|
||||||
|
if (commentInfo.endWrap()) comments.add("");
|
||||||
|
} else if (commentInfo.startWrap() || commentInfo.endWrap()) {
|
||||||
|
comments.add("");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.configuration.setComments(path, comments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user