From 589de2606c3f6066c2004cd76f7e259a1f85cceb Mon Sep 17 00:00:00 2001 From: CarmJos Date: Sat, 23 Apr 2022 23:20:50 +0800 Subject: [PATCH] =?UTF-8?q?[1.0.0]=20=E5=88=9D=E5=A7=8B=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 178 +- README.md | 153 +- .../bukkit/BukkitConfigValue.java | 34 - .../bukkit/builder/AbstractBukkitBuilder.java | 13 - .../bukkit/commented/CommentedEmitter.java | 1513 ----------------- .../bukkit/commented/CommentedYaml.java | 73 - .../commented/CommentedYamlConfiguration.java | 69 - .../bukkit/commented/CommentsProvider.java | 7 - .../bukkit/commented/ConfigComments.java | 34 - .../configuration/bukkit/data/ItemConfig.java | 44 - .../bukkit/data/MessageConfig.java | 8 - .../bukkit/source/BukkitSectionWrapper.java | 18 - .../bukkit/value/ConfiguredItem.java | 24 - .../bukkit/value/ConfiguredMessage.java | 27 - bukkit/pom.xml | 64 + .../lib/configuration/MineConfiguration.java | 33 + .../bukkit/source/BukkitConfigProvider.java | 68 + .../bukkit/source/BukkitYAMLComments.java | 115 ++ bungee/pom.xml | 2 +- .../bungee/BungeeConfigProvider.java | 8 +- {bukkit/common => craftbukkit}/pom.xml | 9 +- .../configuration/craft/CraftConfigValue.java | 33 + .../craft/builder/AbstractCraftBuilder.java | 13 + .../craft/builder/CraftConfigBuilder.java | 8 +- .../serializable/SerializableBuilder.java | 10 +- .../builder/sound/SoundConfigBuilder.java | 12 +- .../configuration/craft/data/ItemConfig.java | 125 ++ .../craft}/data/SoundConfig.java | 34 +- .../craft/source/CraftConfigProvider.java | 19 +- .../craft/source/CraftSectionWrapper.java | 74 + .../craft/value/ConfiguredItem.java | 23 + .../craft}/value/ConfiguredSerializable.java | 13 +- .../craft}/value/ConfiguredSound.java | 28 +- pom.xml | 9 +- spigot/pom.xml | 65 + .../lib/configuration/MineConfiguration.java | 33 + .../spigot/source/SpigotConfigProvider.java | 57 + 37 files changed, 1094 insertions(+), 1956 deletions(-) delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/BukkitConfigValue.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/AbstractBukkitBuilder.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedEmitter.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYaml.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYamlConfiguration.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentsProvider.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/ConfigComments.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/ItemConfig.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/MessageConfig.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitSectionWrapper.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredItem.java delete mode 100644 bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredMessage.java create mode 100644 bukkit/pom.xml create mode 100644 bukkit/src/main/java/cc/carm/lib/configuration/MineConfiguration.java create mode 100644 bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java create mode 100644 bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitYAMLComments.java rename {bukkit/common => craftbukkit}/pom.xml (87%) create mode 100644 craftbukkit/src/main/java/cc/carm/lib/configuration/craft/CraftConfigValue.java create mode 100644 craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/AbstractCraftBuilder.java rename bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/BukkitConfigBuilder.java => craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/CraftConfigBuilder.java (64%) rename {bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit => craftbukkit/src/main/java/cc/carm/lib/configuration/craft}/builder/serializable/SerializableBuilder.java (64%) rename {bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit => craftbukkit/src/main/java/cc/carm/lib/configuration/craft}/builder/sound/SoundConfigBuilder.java (60%) create mode 100644 craftbukkit/src/main/java/cc/carm/lib/configuration/craft/data/ItemConfig.java rename {bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit => craftbukkit/src/main/java/cc/carm/lib/configuration/craft}/data/SoundConfig.java (70%) rename bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java => craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftConfigProvider.java (51%) create mode 100644 craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftSectionWrapper.java create mode 100644 craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredItem.java rename {bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit => craftbukkit/src/main/java/cc/carm/lib/configuration/craft}/value/ConfiguredSerializable.java (82%) rename {bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit => craftbukkit/src/main/java/cc/carm/lib/configuration/craft}/value/ConfiguredSound.java (59%) create mode 100644 spigot/pom.xml create mode 100644 spigot/src/main/java/cc/carm/lib/configuration/MineConfiguration.java create mode 100644 spigot/src/main/java/cc/carm/lib/configuration/spigot/source/SpigotConfigProvider.java diff --git a/LICENSE b/LICENSE index 4cd0986..153d416 100644 --- a/LICENSE +++ b/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. + 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 -copies or substantial portions of the Software. + 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. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + 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. \ No newline at end of file diff --git a/README.md b/README.md index 0292dcf..e2ee6e5 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,138 @@ EasyConfiguration for 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 依赖 + +
+远程库配置 + +```xml + + + + + + + maven + Maven Central + https://repo1.maven.org/maven2 + + + + + EasyConfiguration + GitHub Packages + https://maven.pkg.github.com/CarmJos/MineConfiguration + + + + + carm-repo + Carm's Repo + https://repo.carm.cc/repository/maven-public/ + + + + +``` + +
+ +
+通用原生依赖 + +```xml + + + + + + cc.carm.lib + mineconfiguration-bukkit + [LATEST RELEASE] + compile + + + + cc.carm.lib + mineconfiguration-spigot + [LATEST RELEASE] + compile + + + + cc.carm.lib + mineconfiguration-bungee + [LATEST RELEASE] + compile + + + + +``` + +
+ +#### Gradle 依赖 + +
+远程库配置 + +```groovy +repositories { + + // 采用Maven中心库,安全稳定,但版本更新需要等待同步 + mavenCentral() + + // 采用github依赖库,实时更新,但需要配置 (推荐) + maven { url 'https://maven.pkg.github.com/CarmJos/MineConfiguration' } + + // 采用我的私人依赖库,简单方便,但可能因为变故而无法使用 + maven { url 'https://repo.carm.cc/repository/maven-public/' } +} +``` + +
+ +
+通用原生依赖 + +```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) 开源协议。 - -
-关于 MIT 协议 - -> MIT 协议可能是几大开源协议中最宽松的一个,核心条款是: -> -> 该软件及其相关文档对所有人免费,可以任意处置,包括使用,复制,修改,合并,发表,分发,再授权,或者销售。唯一的限制是,软件中必须包含上述版 权和许可提示。 -> -> 这意味着: -> -> - 你可以自由使用,复制,修改,可以用于自己的项目。 -> - 可以免费分发或用来盈利。 -> - 唯一的限制是必须包含许可声明。 -> -> MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。 -> -> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。* - -
+本项目源码采用 [GNU LESSER GENERAL PUBLIC LICENSE](https://www.gnu.org/licenses/lgpl-3.0.html) 开源协议。 diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/BukkitConfigValue.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/BukkitConfigValue.java deleted file mode 100644 index 9e0cc14..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/BukkitConfigValue.java +++ /dev/null @@ -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 extends CachedConfigValue { - - 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(); - } - - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/AbstractBukkitBuilder.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/AbstractBukkitBuilder.java deleted file mode 100644 index 4f299a3..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/AbstractBukkitBuilder.java +++ /dev/null @@ -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> - extends AbstractConfigBuilder> { - - public AbstractBukkitBuilder() { - super(BukkitConfigProvider.class); - } - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedEmitter.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedEmitter.java deleted file mode 100644 index 1dd8847..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedEmitter.java +++ /dev/null @@ -1,1513 +0,0 @@ -///* -// * Copyright (c) 2008, http://www.snakeyaml.org -// *

-// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// *

-// * http://www.apache.org/licenses/LICENSE-2.0 -// *

-// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//package cc.carm.lib.configuration.bukkit.commented; -// -//import org.yaml.snakeyaml.DumperOptions; -//import org.yaml.snakeyaml.DumperOptions.Version; -//import org.yaml.snakeyaml.emitter.Emitable; -//import org.yaml.snakeyaml.emitter.EmitterException; -//import org.yaml.snakeyaml.emitter.ScalarAnalysis; -//import org.yaml.snakeyaml.error.YAMLException; -//import org.yaml.snakeyaml.events.*; -//import org.yaml.snakeyaml.nodes.Tag; -//import org.yaml.snakeyaml.reader.StreamReader; -//import org.yaml.snakeyaml.scanner.Constant; -//import org.yaml.snakeyaml.util.ArrayStack; -// -//import java.io.IOException; -//import java.io.Writer; -//import java.util.*; -//import java.util.concurrent.ArrayBlockingQueue; -//import java.util.regex.Pattern; -// -///** -// * Copy of {@link org.yaml.snakeyaml.emitter.Emitter} with some ugly hooks. -// */ -//public final class CommentedEmitter implements Emitable { -// public static final int MIN_INDENT = 1; -// public static final int MAX_INDENT = 10; -// private static final Map ESCAPE_REPLACEMENTS = new HashMap<>(); -// private static final char[] SPACE = {' '}; -// private final static Map DEFAULT_TAG_PREFIXES = new LinkedHashMap<>(); -// private final static Pattern HANDLE_FORMAT = Pattern.compile("^![-_\\w]*!$"); -// private final static Pattern ANCHOR_FORMAT = Pattern.compile("^[-_\\w]*$"); -// -// static { -// ESCAPE_REPLACEMENTS.put('\0', "0"); -// ESCAPE_REPLACEMENTS.put('\u0007', "a"); -// ESCAPE_REPLACEMENTS.put('\u0008', "b"); -// ESCAPE_REPLACEMENTS.put('\u0009', "t"); -// ESCAPE_REPLACEMENTS.put('\n', "n"); -// ESCAPE_REPLACEMENTS.put('\u000B', "v"); -// ESCAPE_REPLACEMENTS.put('\u000C', "f"); -// ESCAPE_REPLACEMENTS.put('\r', "r"); -// ESCAPE_REPLACEMENTS.put('\u001B', "e"); -// ESCAPE_REPLACEMENTS.put('"', "\""); -// ESCAPE_REPLACEMENTS.put('\\', "\\"); -// ESCAPE_REPLACEMENTS.put('\u0085', "N"); -// ESCAPE_REPLACEMENTS.put('\u00A0', "_"); -// ESCAPE_REPLACEMENTS.put('\u2028', "L"); -// ESCAPE_REPLACEMENTS.put('\u2029', "P"); -// } -// -// // Encoding is defined by Writer (cannot be overriden by STREAM-START.) -// // private Charset encoding; -// -// static { -// DEFAULT_TAG_PREFIXES.put("!", "!"); -// DEFAULT_TAG_PREFIXES.put(Tag.PREFIX, "!!"); -// } -// -// // The stream should have the methods `write` and possibly `flush`. -// private final Writer stream; -// // Emitter is a state machine with a stack of states to handle nested -// // structures. -// private final ArrayStack states; -// // Current event and the event queue. -// private final Queue events; -// // The current indentation level and the stack of previous indents. -// private final ArrayStack indents; -// // wytrem start -// CommentsProvider commentsProvider; -// // wytrem start -// boolean isInSequence = false; -// Stack paths = new Stack<>(); -// String lastSimpleKey; -// private EmitterState state; -// private Event event; -// private Integer indent; -// // Flow level. -// private int flowLevel; -// // Contexts. -// private boolean rootContext; -// private boolean mappingContext; -// private boolean simpleKeyContext; -// // -// // Characteristics of the last emitted character: -// // - current position. -// // - is it a whitespace? -// // - is it an indention character -// // (indentation space, '-', '?', or ':')? -// // private int line; this variable is not used -// private int column; -// private boolean whitespace; -// private boolean indention; -// private boolean openEnded; -// // Formatting details. -// private final Boolean canonical; -// // pretty print flow by adding extra line breaks -// private final Boolean prettyFlow; -// private final boolean allowUnicode; -// private int bestIndent; -// private final int indicatorIndent; -// private int bestWidth; -// private final char[] bestLineBreak; -// private final boolean splitLines; -// // wytrem end -// // Tag prefixes. -// private Map tagPrefixes; -// // Prepared anchor and tag. -// private String preparedAnchor; -// private String preparedTag; -// // Scalar analysis and style. -// private ScalarAnalysis analysis; -// // wytrem end -// private DumperOptions.ScalarStyle style; -// -// // In some cases, we wait for a few next events before emitting. -// -// public CommentedEmitter(Writer stream, DumperOptions opts, CommentsProvider commentsProvider) { // wytrem -// // wytrem start -// this.commentsProvider = commentsProvider; -// // wytrem end -// -// // The stream should have the methods `write` and possibly `flush`. -// this.stream = stream; -// // Emitter is a state machine with a stack of states to handle nested -// // structures. -// this.states = new ArrayStack<>(100); -// this.state = new ExpectStreamStart(); -// // Current event and the event queue. -// this.events = new ArrayBlockingQueue<>(100); -// this.event = null; -// // The current indentation level and the stack of previous indents. -// this.indents = new ArrayStack<>(10); -// this.indent = null; -// // Flow level. -// this.flowLevel = 0; -// // Contexts. -// mappingContext = false; -// simpleKeyContext = false; -// -// // -// // Characteristics of the last emitted character: -// // - current position. -// // - is it a whitespace? -// // - is it an indention character -// // (indentation space, '-', '?', or ':')? -// column = 0; -// whitespace = true; -// indention = true; -// -// // Whether the document requires an explicit document indicator -// openEnded = false; -// -// // Formatting details. -// this.canonical = opts.isCanonical(); -// this.prettyFlow = opts.isPrettyFlow(); -// this.allowUnicode = opts.isAllowUnicode(); -// this.bestIndent = 2; -// if ((opts.getIndent() > MIN_INDENT) && (opts.getIndent() < MAX_INDENT)) { -// this.bestIndent = opts.getIndent(); -// } -// this.indicatorIndent = opts.getIndicatorIndent(); -// this.bestWidth = 80; -// if (opts.getWidth() > this.bestIndent * 2) { -// this.bestWidth = opts.getWidth(); -// } -// this.bestLineBreak = opts.getLineBreak().getString().toCharArray(); -// this.splitLines = opts.getSplitLines(); -// -// // Tag prefixes. -// this.tagPrefixes = new LinkedHashMap<>(); -// -// // Prepared anchor and tag. -// this.preparedAnchor = null; -// this.preparedTag = null; -// -// // Scalar analysis and style. -// this.analysis = null; -// this.style = null; -// } -// -// static String prepareAnchor(String anchor) { -// if (anchor.length() == 0) { -// throw new EmitterException("anchor must not be empty"); -// } -// if (!ANCHOR_FORMAT.matcher(anchor).matches()) { -// throw new EmitterException("invalid character in the anchor: " + anchor); -// } -// return anchor; -// } -// -// public void emit(Event event) throws IOException { -// this.events.add(event); -// -// while (!needMoreEvents()) { -// this.event = this.events.poll(); -// // wytrem start -// if (this.event instanceof SequenceStartEvent) { -// this.isInSequence = true; -// } -// -// if (this.event instanceof SequenceEndEvent) { -// this.isInSequence = false; -// } -// -// if (this.event instanceof MappingStartEvent) { -// if (!this.isInSequence) { -// if (lastSimpleKey != null) { -// this.paths.push(lastSimpleKey); -// } -// } -// } -// -// if (this.event instanceof MappingEndEvent) { -// if (!this.isInSequence) { -// if (!this.paths.isEmpty()) { -// this.paths.pop(); -// } -// } -// } -// // wytrem end -// this.state.expect(); -// this.event = null; -// } -// } -// -// // States -// -// // Stream handlers. -// -// private boolean needMoreEvents() { -// if (events.isEmpty()) { -// return true; -// } -// Event event = events.peek(); -// if (event instanceof DocumentStartEvent) { -// return needEvents(1); -// } else if (event instanceof SequenceStartEvent) { -// return needEvents(2); -// } else if (event instanceof MappingStartEvent) { -// return needEvents(3); -// } else { -// return false; -// } -// } -// -// private boolean needEvents(int count) { -// int level = 0; -// Iterator iter = events.iterator(); -// iter.next(); -// while (iter.hasNext()) { -// Event event = iter.next(); -// if (event instanceof DocumentStartEvent || event instanceof CollectionStartEvent) { -// level++; -// } else if (event instanceof DocumentEndEvent || event instanceof CollectionEndEvent) { -// level--; -// } else if (event instanceof StreamEndEvent) { -// level = -1; -// } -// if (level < 0) { -// return false; -// } -// } -// return events.size() < count + 1; -// } -// -// // Document handlers. -// -// private void increaseIndent(boolean flow, boolean indentless) { -// indents.push(indent); -// if (indent == null) { -// if (flow) { -// indent = bestIndent; -// } else { -// indent = 0; -// } -// } else if (!indentless) { -// this.indent += bestIndent; -// } -// } -// -// private void expectNode(boolean root, boolean mapping, boolean simpleKey) throws IOException { -// rootContext = root; -// mappingContext = mapping; -// simpleKeyContext = simpleKey; -// if (event instanceof AliasEvent) { -// expectAlias(); -// } else if (event instanceof ScalarEvent || event instanceof CollectionStartEvent) { -// processAnchor("&"); -// processTag(); -// if (event instanceof ScalarEvent) { -// expectScalar(); -// } else if (event instanceof SequenceStartEvent) { -// if (flowLevel != 0 || canonical || ((SequenceStartEvent) event).isFlow() -// || checkEmptySequence()) { -// expectFlowSequence(); -// } else { -// expectBlockSequence(); -// } -// } else {// MappingStartEvent -// if (flowLevel != 0 || canonical || ((MappingStartEvent) event).isFlow() -// || checkEmptyMapping()) { -// expectFlowMapping(); -// } else { -// expectBlockMapping(); -// } -// } -// } else { -// throw new EmitterException("expected NodeEvent, but got " + event); -// } -// } -// -// private void expectAlias() throws IOException { -// if (((NodeEvent) event).getAnchor() == null) { -// throw new EmitterException("anchor is not specified for alias"); -// } -// processAnchor("*"); -// state = states.pop(); -// } -// -// private void expectScalar() throws IOException { -// // wytrem start -// if (simpleKeyContext) { -// String scalar = analyzeScalar(((ScalarEvent) event).getValue()).getScalar(); -// String path = scalar; -// -// if (!this.paths.isEmpty()) { -// path = String.join(".", this.paths) + "." + path; -// } -// -// String[] comments = this.commentsProvider.apply(path); -// if (comments != null && comments.length > 0) { -// writeLineBreak(null); -// for (String line : comments) { -// if (line.contains("\n")) { -// throw new IllegalArgumentException("Unexpected \\n in comment line."); -// } -// writeIndent(); -// stream.write("# " + line); -// writeLineBreak(null); -// } -// writeIndent(); -// } -// -// lastSimpleKey = scalar; -// } -// // wytrem end -// -// increaseIndent(true, false); -// processScalar(); -// indent = indents.pop(); -// state = states.pop(); -// } -// -// // Node handlers. -// -// private void expectFlowSequence() throws IOException { -// writeIndicator("[", true, true, false); -// flowLevel++; -// increaseIndent(true, false); -// if (prettyFlow) { -// writeIndent(); -// } -// state = new ExpectFirstFlowSequenceItem(); -// } -// -// private void expectFlowMapping() throws IOException { -// writeIndicator("{", true, true, false); -// flowLevel++; -// increaseIndent(true, false); -// if (prettyFlow) { -// writeIndent(); -// } -// state = new ExpectFirstFlowMappingKey(); -// } -// -// private void expectBlockSequence() { -// boolean indentless = mappingContext && !indention; -// increaseIndent(false, indentless); -// state = new ExpectFirstBlockSequenceItem(); -// } -// -// // Flow sequence handlers. -// -// // Block mapping handlers. -// private void expectBlockMapping() { -// increaseIndent(false, false); -// state = new ExpectFirstBlockMappingKey(); -// } -// -// private boolean checkEmptySequence() { -// return event instanceof SequenceStartEvent && !events.isEmpty() && events.peek() instanceof SequenceEndEvent; -// } -// -// private boolean checkEmptyMapping() { -// return event instanceof MappingStartEvent && !events.isEmpty() && events.peek() instanceof MappingEndEvent; -// } -// -// // Flow mapping handlers. -// -// private boolean checkEmptyDocument() { -// if (!(event instanceof DocumentStartEvent) || events.isEmpty()) { -// return false; -// } -// Event event = events.peek(); -// if (event instanceof ScalarEvent) { -// ScalarEvent e = (ScalarEvent) event; -// return e.getAnchor() == null && e.getTag() == null && e.getImplicit() != null && e -// .getValue().length() == 0; -// } -// return false; -// } -// -// private boolean checkSimpleKey() { -// int length = 0; -// if (event instanceof NodeEvent && ((NodeEvent) event).getAnchor() != null) { -// if (preparedAnchor == null) { -// preparedAnchor = prepareAnchor(((NodeEvent) event).getAnchor()); -// } -// length += preparedAnchor.length(); -// } -// String tag = null; -// if (event instanceof ScalarEvent) { -// tag = ((ScalarEvent) event).getTag(); -// } else if (event instanceof CollectionStartEvent) { -// tag = ((CollectionStartEvent) event).getTag(); -// } -// if (tag != null) { -// if (preparedTag == null) { -// preparedTag = prepareTag(tag); -// } -// length += preparedTag.length(); -// } -// if (event instanceof ScalarEvent) { -// if (analysis == null) { -// analysis = analyzeScalar(((ScalarEvent) event).getValue()); -// } -// length += analysis.getScalar().length(); -// } -// return length < 128 && (event instanceof AliasEvent -// || (event instanceof ScalarEvent && !analysis.isEmpty() && !analysis.isMultiline()) -// || checkEmptySequence() || checkEmptyMapping()); -// } -// -// private void processAnchor(String indicator) throws IOException { -// NodeEvent ev = (NodeEvent) event; -// if (ev.getAnchor() == null) { -// preparedAnchor = null; -// return; -// } -// if (preparedAnchor == null) { -// preparedAnchor = prepareAnchor(ev.getAnchor()); -// } -// writeIndicator(indicator + preparedAnchor, true, false, false); -// preparedAnchor = null; -// } -// -// private void processTag() throws IOException { -// String tag; -// if (event instanceof ScalarEvent) { -// ScalarEvent ev = (ScalarEvent) event; -// tag = ev.getTag(); -// if (style == null) { -// style = chooseScalarStyle(); -// } -// if ((!canonical || tag == null) && ((style == null && ev.getImplicit() -// .canOmitTagInPlainScalar()) || (style != null && ev.getImplicit() -// .canOmitTagInNonPlainScalar()))) { -// preparedTag = null; -// return; -// } -// if (ev.getImplicit().canOmitTagInPlainScalar() && tag == null) { -// tag = "!"; -// preparedTag = null; -// } -// } else { -// CollectionStartEvent ev = (CollectionStartEvent) event; -// tag = ev.getTag(); -// if ((!canonical || tag == null) && ev.getImplicit()) { -// preparedTag = null; -// return; -// } -// } -// if (tag == null) { -// throw new EmitterException("tag is not specified"); -// } -// if (preparedTag == null) { -// preparedTag = prepareTag(tag); -// } -// writeIndicator(preparedTag, true, false, false); -// preparedTag = null; -// } -// -// private DumperOptions.ScalarStyle chooseScalarStyle() { -// ScalarEvent ev = (ScalarEvent) event; -// if (analysis == null) { -// analysis = analyzeScalar(ev.getValue()); -// } -// -// if (!ev.isPlain() && ev.getScalarStyle() == DumperOptions.ScalarStyle.DOUBLE_QUOTED || this.canonical) { -// return DumperOptions.ScalarStyle.DOUBLE_QUOTED; -// } -// if (ev.isPlain() && ev.getImplicit().canOmitTagInPlainScalar()) { -// if (!(simpleKeyContext && (analysis.isEmpty() || analysis.isMultiline())) -// && ((flowLevel != 0 && analysis.isAllowFlowPlain()) || (flowLevel == 0 && analysis.isAllowBlockPlain()))) { -// return null; -// } -// } -// if (!ev.isPlain() && (ev.getScalarStyle() == DumperOptions.ScalarStyle.LITERAL || ev.getScalarStyle() == DumperOptions.ScalarStyle.FOLDED)) { -// if (flowLevel == 0 && !simpleKeyContext && analysis.isAllowBlock()) { -// return ev.getScalarStyle(); -// } -// } -// if (ev.isPlain() || ev.getScalarStyle() == DumperOptions.ScalarStyle.SINGLE_QUOTED) { -// if (analysis.isAllowSingleQuoted() && !(simpleKeyContext && analysis.isMultiline())) { -// return DumperOptions.ScalarStyle.SINGLE_QUOTED; -// } -// } -// return DumperOptions.ScalarStyle.DOUBLE_QUOTED; -// } -// -// // Block sequence handlers. -// -// private void processScalar() throws IOException { -// ScalarEvent ev = (ScalarEvent) event; -// -// if (analysis == null) { -// analysis = analyzeScalar(ev.getValue()); -// } -// if (style == null) { -// style = chooseScalarStyle(); -// } -// boolean split = !simpleKeyContext && splitLines; -// if (style == null) { -// -// writePlain(analysis.getScalar(), split); -// } else { -// switch (style) { -// case DOUBLE_QUOTED: -// writeDoubleQuoted(analysis.getScalar(), split); -// break; -// case SINGLE_QUOTED: -// writeSingleQuoted(analysis.getScalar(), split); -// break; -// case FOLDED: -// writeFolded(analysis.getScalar(), split); -// break; -// case LITERAL: -// writeLiteral(analysis.getScalar()); -// break; -// default: -// throw new YAMLException("Unexpected style: " + style); -// } -// } -// analysis = null; -// style = null; -// } -// -// private String prepareVersion(Version version) { -// if (version.major() != 1) { -// throw new EmitterException("unsupported YAML version: " + version); -// } -// return version.getRepresentation(); -// } -// -// private String prepareTagHandle(String handle) { -// if (handle.length() == 0) { -// throw new EmitterException("tag handle must not be empty"); -// } else if (handle.charAt(0) != '!' || handle.charAt(handle.length() - 1) != '!') { -// throw new EmitterException("tag handle must start and end with '!': " + handle); -// } else if (!"!".equals(handle) && !HANDLE_FORMAT.matcher(handle).matches()) { -// throw new EmitterException("invalid character in the tag handle: " + handle); -// } -// return handle; -// } -// -// private String prepareTagPrefix(String prefix) { -// if (prefix.length() == 0) { -// throw new EmitterException("tag prefix must not be empty"); -// } -// StringBuilder chunks = new StringBuilder(); -// int start = 0; -// int end = 0; -// if (prefix.charAt(0) == '!') { -// end = 1; -// } -// while (end < prefix.length()) { -// end++; -// } -// chunks.append(prefix, start, end); -// return chunks.toString(); -// } -// -// private String prepareTag(String tag) { -// if (tag.length() == 0) { -// throw new EmitterException("tag must not be empty"); -// } -// if ("!".equals(tag)) { -// return tag; -// } -// String handle = null; -// String suffix = tag; -// // shall the tag prefixes be sorted as in PyYAML? -// for (String prefix : tagPrefixes.keySet()) { -// if (tag.startsWith(prefix) && ("!".equals(prefix) || prefix.length() < tag.length())) { -// handle = prefix; -// } -// } -// if (handle != null) { -// suffix = tag.substring(handle.length()); -// handle = tagPrefixes.get(handle); -// } -// -// int end = suffix.length(); -// String suffixText = end > 0 ? suffix.substring(0, end) : ""; -// -// if (handle != null) { -// return handle + suffixText; -// } -// return "!<" + suffixText + ">"; -// } -// -// private ScalarAnalysis analyzeScalar(String scalar) { -// // Empty scalar is a special case. -// if (scalar.length() == 0) { -// return new ScalarAnalysis(scalar, true, false, false, true, true, false); -// } -// // Indicators and special characters. -// boolean blockIndicators = false; -// boolean flowIndicators = false; -// boolean lineBreaks = false; -// boolean specialCharacters = false; -// -// // Important whitespace combinations. -// boolean leadingSpace = false; -// boolean leadingBreak = false; -// boolean trailingSpace = false; -// boolean trailingBreak = false; -// boolean breakSpace = false; -// boolean spaceBreak = false; -// -// // Check document indicators. -// if (scalar.startsWith("---") || scalar.startsWith("...")) { -// blockIndicators = true; -// flowIndicators = true; -// } -// // First character or preceded by a whitespace. -// boolean preceededByWhitespace = true; -// boolean followedByWhitespace = scalar.length() == 1 || Constant.NULL_BL_T_LINEBR.has(scalar.codePointAt(1)); -// // The previous character is a space. -// boolean previousSpace = false; -// -// // The previous character is a break. -// boolean previousBreak = false; -// -// int index = 0; -// -// while (index < scalar.length()) { -// int c = scalar.codePointAt(index); -// // Check for indicators. -// if (index == 0) { -// // Leading indicators are special characters. -// if ("#,[]{}&*!|>'\"%@`".indexOf(c) != -1) { -// flowIndicators = true; -// blockIndicators = true; -// } -// if (c == '?' || c == ':') { -// flowIndicators = true; -// if (followedByWhitespace) { -// blockIndicators = true; -// } -// } -// if (c == '-' && followedByWhitespace) { -// flowIndicators = true; -// blockIndicators = true; -// } -// } else { -// // Some indicators cannot appear within a scalar as well. -// if (",?[]{}".indexOf(c) != -1) { -// flowIndicators = true; -// } -// if (c == ':') { -// flowIndicators = true; -// if (followedByWhitespace) { -// blockIndicators = true; -// } -// } -// if (c == '#' && preceededByWhitespace) { -// flowIndicators = true; -// blockIndicators = true; -// } -// } -// // Check for line breaks, special, and unicode characters. -// boolean isLineBreak = Constant.LINEBR.has(c); -// if (isLineBreak) { -// lineBreaks = true; -// } -// if (!(c == '\n' || (0x20 <= c && c <= 0x7E))) { -// if (c == 0x85 || (c >= 0xA0 && c <= 0xD7FF) -// || (c >= 0xE000 && c <= 0xFFFD) -// || (c >= 0x10000 && c <= 0x10FFFF)) { -// // unicode is used -// if (!this.allowUnicode) { -// specialCharacters = true; -// } -// } else { -// specialCharacters = true; -// } -// } -// // Detect important whitespace combinations. -// if (c == ' ') { -// if (index == 0) { -// leadingSpace = true; -// } -// if (index == scalar.length() - 1) { -// trailingSpace = true; -// } -// if (previousBreak) { -// breakSpace = true; -// } -// previousSpace = true; -// previousBreak = false; -// } else if (isLineBreak) { -// if (index == 0) { -// leadingBreak = true; -// } -// if (index == scalar.length() - 1) { -// trailingBreak = true; -// } -// if (previousSpace) { -// spaceBreak = true; -// } -// previousSpace = false; -// previousBreak = true; -// } else { -// previousSpace = false; -// previousBreak = false; -// } -// -// // Prepare for the next character. -// index += Character.charCount(c); -// preceededByWhitespace = Constant.NULL_BL_T.has(c) || isLineBreak; -// followedByWhitespace = true; -// if (index + 1 < scalar.length()) { -// int nextIndex = index + Character.charCount(scalar.codePointAt(index)); -// if (nextIndex < scalar.length()) { -// followedByWhitespace = (Constant.NULL_BL_T.has(scalar.codePointAt(nextIndex))) || isLineBreak; -// } -// } -// } -// // Let's decide what styles are allowed. -// boolean allowFlowPlain = true; -// boolean allowBlockPlain = true; -// boolean allowSingleQuoted = true; -// boolean allowBlock = true; -// // Leading and trailing whitespaces are bad for plain scalars. -// if (leadingSpace || leadingBreak || trailingSpace || trailingBreak) { -// allowFlowPlain = allowBlockPlain = false; -// } -// // We do not permit trailing spaces for block scalars. -// if (trailingSpace) { -// allowBlock = false; -// } -// // Spaces at the beginning of a new line are only acceptable for block -// // scalars. -// if (breakSpace) { -// allowFlowPlain = allowBlockPlain = allowSingleQuoted = false; -// } -// // Spaces followed by breaks, as well as special character are only -// // allowed for double quoted scalars. -// if (spaceBreak || specialCharacters) { -// allowFlowPlain = allowBlockPlain = allowSingleQuoted = allowBlock = false; -// } -// // Although the plain scalar writer supports breaks, we never emit -// // multiline plain scalars in the flow context. -// if (lineBreaks) { -// allowFlowPlain = false; -// } -// // Flow indicators are forbidden for flow plain scalars. -// if (flowIndicators) { -// allowFlowPlain = false; -// } -// // Block indicators are forbidden for block plain scalars. -// if (blockIndicators) { -// allowBlockPlain = false; -// } -// -// return new ScalarAnalysis(scalar, false, lineBreaks, allowFlowPlain, allowBlockPlain, -// allowSingleQuoted, allowBlock); -// } -// -// void flushStream() throws IOException { -// stream.flush(); -// } -// -// void writeStreamStart() { -// // BOM is written by Writer. -// } -// -// // Checkers. -// -// void writeStreamEnd() throws IOException { -// flushStream(); -// } -// -// void writeIndicator(String indicator, boolean needWhitespace, boolean whitespace, -// boolean indentation) throws IOException { -// if (!this.whitespace && needWhitespace) { -// this.column++; -// stream.write(SPACE); -// } -// this.whitespace = whitespace; -// this.indention = this.indention && indentation; -// this.column += indicator.length(); -// openEnded = false; -// stream.write(indicator); -// } -// -// void writeIndent() throws IOException { -// int indent; -// if (this.indent != null) { -// indent = this.indent; -// } else { -// indent = 0; -// } -// -// if (!this.indention || this.column > indent || (this.column == indent && !this.whitespace)) { -// writeLineBreak(null); -// } -// -// writeWhitespace(indent - this.column); -// } -// -// private void writeWhitespace(int length) throws IOException { -// if (length <= 0) { -// return; -// } -// this.whitespace = true; -// char[] data = new char[length]; -// Arrays.fill(data, ' '); -// this.column += length; -// stream.write(data); -// } -// -// // Anchor, Tag, and Scalar processors. -// -// private void writeLineBreak(String data) throws IOException { -// this.whitespace = true; -// this.indention = true; -// this.column = 0; -// if (data == null) { -// stream.write(this.bestLineBreak); -// } else { -// stream.write(data); -// } -// } -// -// void writeVersionDirective(String versionText) throws IOException { -// stream.write("%YAML "); -// stream.write(versionText); -// writeLineBreak(null); -// } -// -// void writeTagDirective(String handleText, String prefixText) throws IOException { -// // XXX: not sure 4 invocations better than StringBuilders created by str -// // + str -// stream.write("%TAG "); -// stream.write(handleText); -// stream.write(SPACE); -// stream.write(prefixText); -// writeLineBreak(null); -// } -// -// // Scalar streams. -// private void writeSingleQuoted(String text, boolean split) throws IOException { -// writeIndicator("'", true, false, false); -// boolean spaces = false; -// boolean breaks = false; -// int start = 0, end = 0; -// char ch; -// while (end <= text.length()) { -// ch = 0; -// if (end < text.length()) { -// ch = text.charAt(end); -// } -// if (spaces) { -// if (ch != ' ') { -// if (start + 1 == end && this.column > this.bestWidth && split && start != 0 -// && end != text.length()) { -// writeIndent(); -// } else { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// } -// start = end; -// } -// } else if (breaks) { -// if (ch == 0 || Constant.LINEBR.hasNo(ch)) { -// nextLine(text, start, end); -// start = end; -// } -// } else { -// if (Constant.LINEBR.has(ch, "\0 '")) { -// if (start < end) { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// start = end; -// } -// } -// } -// if (ch == '\'') { -// this.column += 2; -// stream.write("''"); -// start = end + 1; -// } -// if (ch != 0) { -// spaces = ch == ' '; -// breaks = Constant.LINEBR.has(ch); -// } -// end++; -// } -// writeIndicator("'", false, false, false); -// } -// -// private void nextLine(String text, int start, int end) throws IOException { -// if (text.charAt(start) == '\n') { -// writeLineBreak(null); -// } -// String data = text.substring(start, end); -// for (char br : data.toCharArray()) { -// if (br == '\n') { -// writeLineBreak(null); -// } else { -// writeLineBreak(String.valueOf(br)); -// } -// } -// writeIndent(); -// } -// -// // Analyzers. -// -// private void writeDoubleQuoted(String text, boolean split) throws IOException { -// writeIndicator("\"", true, false, false); -// int start = 0; -// int end = 0; -// while (end <= text.length()) { -// Character ch = null; -// if (end < text.length()) { -// ch = text.charAt(end); -// } -// if (ch == null || "\"\\\u0085\u2028\u2029\uFEFF".indexOf(ch) != -1 -// || !('\u0020' <= ch && ch <= '\u007E')) { -// if (start < end) { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// start = end; -// } -// if (ch != null) { -// String data; -// if (ESCAPE_REPLACEMENTS.containsKey(ch)) { -// data = "\\" + ESCAPE_REPLACEMENTS.get(ch); -// } else if (!this.allowUnicode || !StreamReader.isPrintable(ch)) { -// // if !allowUnicode or the character is not printable, -// // we must encode it -// if (ch <= '\u00FF') { -// String s = "0" + Integer.toString(ch, 16); -// data = "\\x" + s.substring(s.length() - 2); -// } else if (ch >= '\uD800' && ch <= '\uDBFF') { -// if (end + 1 < text.length()) { -// char ch2 = text.charAt(++end); -// String s = "000" + Long.toHexString(Character.toCodePoint(ch, ch2)); -// data = "\\U" + s.substring(s.length() - 8); -// } else { -// String s = "000" + Integer.toString(ch, 16); -// data = "\\u" + s.substring(s.length() - 4); -// } -// } else { -// String s = "000" + Integer.toString(ch, 16); -// data = "\\u" + s.substring(s.length() - 4); -// } -// } else { -// data = String.valueOf(ch); -// } -// this.column += data.length(); -// stream.write(data); -// start = end + 1; -// } -// } -// if ((0 < end && end < (text.length() - 1)) && (ch == ' ' || start >= end) -// && (this.column + (end - start)) > this.bestWidth && split) { -// String data; -// if (start >= end) { -// data = "\\"; -// } else { -// data = text.substring(start, end) + "\\"; -// } -// if (start < end) { -// start = end; -// } -// this.column += data.length(); -// stream.write(data); -// writeIndent(); -// this.whitespace = false; -// this.indention = false; -// if (text.charAt(start) == ' ') { -// data = "\\"; -// this.column += data.length(); -// stream.write(data); -// } -// } -// end += 1; -// } -// writeIndicator("\"", false, false, false); -// } -// -// private String determineBlockHints(String text) { -// StringBuilder hints = new StringBuilder(); -// if (Constant.LINEBR.has(text.charAt(0), " ")) { -// hints.append(bestIndent); -// } -// char ch1 = text.charAt(text.length() - 1); -// if (Constant.LINEBR.hasNo(ch1)) { -// hints.append("-"); -// } else if (text.length() == 1 || Constant.LINEBR.has(text.charAt(text.length() - 2))) { -// hints.append("+"); -// } -// return hints.toString(); -// } -// -// void writeFolded(String text, boolean split) throws IOException { -// String hints = determineBlockHints(text); -// writeIndicator(">" + hints, true, false, false); -// if (hints.length() > 0 && (hints.charAt(hints.length() - 1) == '+')) { -// openEnded = true; -// } -// writeLineBreak(null); -// boolean leadingSpace = true; -// boolean spaces = false; -// boolean breaks = true; -// int start = 0, end = 0; -// while (end <= text.length()) { -// char ch = 0; -// if (end < text.length()) { -// ch = text.charAt(end); -// } -// if (breaks) { -// if (ch == 0 || Constant.LINEBR.hasNo(ch)) { -// if (!leadingSpace && ch != 0 && ch != ' ' && text.charAt(start) == '\n') { -// writeLineBreak(null); -// } -// leadingSpace = ch == ' '; -// String data = text.substring(start, end); -// for (char br : data.toCharArray()) { -// if (br == '\n') { -// writeLineBreak(null); -// } else { -// writeLineBreak(String.valueOf(br)); -// } -// } -// if (ch != 0) { -// writeIndent(); -// } -// start = end; -// } -// } else if (spaces) { -// if (ch != ' ') { -// if (start + 1 == end && this.column > this.bestWidth && split) { -// writeIndent(); -// } else { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// } -// start = end; -// } -// } else { -// if (Constant.LINEBR.has(ch, "\0 ")) { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// if (ch == 0) { -// writeLineBreak(null); -// } -// start = end; -// } -// } -// if (ch != 0) { -// breaks = Constant.LINEBR.has(ch); -// spaces = ch == ' '; -// } -// end++; -// } -// } -// -// void writeLiteral(String text) throws IOException { -// String hints = determineBlockHints(text); -// writeIndicator("|" + hints, true, false, false); -// if (hints.length() > 0 && (hints.charAt(hints.length() - 1)) == '+') { -// openEnded = true; -// } -// writeLineBreak(null); -// boolean breaks = true; -// int start = 0, end = 0; -// while (end <= text.length()) { -// char ch = 0; -// if (end < text.length()) { -// ch = text.charAt(end); -// } -// if (breaks) { -// if (ch == 0 || Constant.LINEBR.hasNo(ch)) { -// String data = text.substring(start, end); -// for (char br : data.toCharArray()) { -// if (br == '\n') { -// writeLineBreak(null); -// } else { -// writeLineBreak(String.valueOf(br)); -// } -// } -// if (ch != 0) { -// writeIndent(); -// } -// start = end; -// } -// } else { -// if (ch == 0 || Constant.LINEBR.has(ch)) { -// stream.write(text, start, end - start); -// if (ch == 0) { -// writeLineBreak(null); -// } -// start = end; -// } -// } -// if (ch != 0) { -// breaks = Constant.LINEBR.has(ch); -// } -// end++; -// } -// } -// -// void writePlain(String text, boolean split) throws IOException { -// if (rootContext) { -// openEnded = true; -// } -// if (text.length() == 0) { -// return; -// } -// if (!this.whitespace) { -// this.column++; -// stream.write(SPACE); -// } -// this.whitespace = false; -// this.indention = false; -// boolean spaces = false; -// boolean breaks = false; -// int start = 0, end = 0; -// while (end <= text.length()) { -// char ch = 0; -// if (end < text.length()) { -// ch = text.charAt(end); -// } -// if (spaces) { -// if (ch != ' ') { -// if (start + 1 == end && this.column > this.bestWidth && split) { -// writeIndent(); -// this.whitespace = false; -// this.indention = false; -// } else { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// } -// start = end; -// } -// } else if (breaks) { -// if (Constant.LINEBR.hasNo(ch)) { -// nextLine(text, start, end); -// this.whitespace = false; -// this.indention = false; -// start = end; -// } -// } else { -// if (Constant.LINEBR.has(ch, "\0 ")) { -// int len = end - start; -// this.column += len; -// stream.write(text, start, len); -// start = end; -// } -// } -// if (ch != 0) { -// spaces = ch == ' '; -// breaks = Constant.LINEBR.has(ch); -// } -// end++; -// } -// } -// -// /** -// * -// */ -// public interface EmitterState { -// void expect() throws IOException; -// } -// -// private class ExpectStreamStart implements EmitterState { -// public void expect() { -// if (event instanceof StreamStartEvent) { -// writeStreamStart(); -// state = new ExpectFirstDocumentStart(); -// } else { -// throw new EmitterException("expected StreamStartEvent, but got " + event); -// } -// } -// } -// -// private class ExpectNothing implements EmitterState { -// public void expect() { -// throw new EmitterException("expecting nothing, but got " + event); -// } -// } -// -// // Writers. -// -// private class ExpectFirstDocumentStart implements EmitterState { -// public void expect() throws IOException { -// new ExpectDocumentStart(true).expect(); -// } -// } -// -// private class ExpectDocumentStart implements EmitterState { -// private final boolean first; -// -// public ExpectDocumentStart(boolean first) { -// this.first = first; -// } -// -// public void expect() throws IOException { -// if (event instanceof DocumentStartEvent) { -// DocumentStartEvent ev = (DocumentStartEvent) event; -// if ((ev.getVersion() != null || ev.getTags() != null) && openEnded) { -// writeIndicator("...", true, false, false); -// writeIndent(); -// } -// if (ev.getVersion() != null) { -// String versionText = prepareVersion(ev.getVersion()); -// writeVersionDirective(versionText); -// } -// tagPrefixes = new LinkedHashMap<>(DEFAULT_TAG_PREFIXES); -// if (ev.getTags() != null) { -// Set handles = new TreeSet<>(ev.getTags().keySet()); -// for (String handle : handles) { -// String prefix = ev.getTags().get(handle); -// tagPrefixes.put(prefix, handle); -// String handleText = prepareTagHandle(handle); -// String prefixText = prepareTagPrefix(prefix); -// writeTagDirective(handleText, prefixText); -// } -// } -// boolean implicit = first && !ev.getExplicit() && !canonical -// && ev.getVersion() == null -// && (ev.getTags() == null || ev.getTags().isEmpty()) -// && !checkEmptyDocument(); -// if (!implicit) { -// writeIndent(); -// writeIndicator("---", true, false, false); -// if (canonical) { -// writeIndent(); -// } -// } -// state = new ExpectDocumentRoot(); -// } else if (event instanceof StreamEndEvent) { -// // fix 313 PyYAML changeset -// // if (openEnded) { -// // writeIndicator("...", true, false, false); -// // writeIndent(); -// // } -// writeStreamEnd(); -// state = new ExpectNothing(); -// } else { -// throw new EmitterException("expected DocumentStartEvent, but got " + event); -// } -// } -// } -// -// private class ExpectDocumentEnd implements EmitterState { -// public void expect() throws IOException { -// if (event instanceof DocumentEndEvent) { -// writeIndent(); -// if (((DocumentEndEvent) event).getExplicit()) { -// writeIndicator("...", true, false, false); -// writeIndent(); -// } -// flushStream(); -// state = new ExpectDocumentStart(false); -// } else { -// throw new EmitterException("expected DocumentEndEvent, but got " + event); -// } -// } -// } -// -// private class ExpectDocumentRoot implements EmitterState { -// public void expect() throws IOException { -// states.push(new ExpectDocumentEnd()); -// expectNode(true, false, false); -// } -// } -// -// private class ExpectFirstFlowSequenceItem implements EmitterState { -// public void expect() throws IOException { -// if (event instanceof SequenceEndEvent) { -// indent = indents.pop(); -// flowLevel--; -// writeIndicator("]", false, false, false); -// state = states.pop(); -// } else { -// if (canonical || (column > bestWidth && splitLines) || prettyFlow) { -// writeIndent(); -// } -// states.push(new ExpectFlowSequenceItem()); -// expectNode(false, false, false); -// } -// } -// } -// -// private class ExpectFlowSequenceItem implements EmitterState { -// public void expect() throws IOException { -// if (event instanceof SequenceEndEvent) { -// indent = indents.pop(); -// flowLevel--; -// if (canonical) { -// writeIndicator(",", false, false, false); -// writeIndent(); -// } -// writeIndicator("]", false, false, false); -// if (prettyFlow) { -// writeIndent(); -// } -// state = states.pop(); -// } else { -// writeIndicator(",", false, false, false); -// if (canonical || (column > bestWidth && splitLines) || prettyFlow) { -// writeIndent(); -// } -// states.push(new ExpectFlowSequenceItem()); -// expectNode(false, false, false); -// } -// } -// } -// -// private class ExpectFirstFlowMappingKey implements EmitterState { -// public void expect() throws IOException { -// if (event instanceof MappingEndEvent) { -// indent = indents.pop(); -// flowLevel--; -// writeIndicator("}", false, false, false); -// state = states.pop(); -// } else { -// if (canonical || (column > bestWidth && splitLines) || prettyFlow) { -// writeIndent(); -// } -// if (!canonical && checkSimpleKey()) { -// states.push(new ExpectFlowMappingSimpleValue()); -// expectNode(false, true, true); -// } else { -// writeIndicator("?", true, false, false); -// states.push(new ExpectFlowMappingValue()); -// expectNode(false, true, false); -// } -// } -// } -// } -// -// private class ExpectFlowMappingKey implements EmitterState { -// public void expect() throws IOException { -// if (event instanceof MappingEndEvent) { -// indent = indents.pop(); -// flowLevel--; -// if (canonical) { -// writeIndicator(",", false, false, false); -// writeIndent(); -// } -// if (prettyFlow) { -// writeIndent(); -// } -// writeIndicator("}", false, false, false); -// state = states.pop(); -// } else { -// writeIndicator(",", false, false, false); -// if (canonical || (column > bestWidth && splitLines) || prettyFlow) { -// writeIndent(); -// } -// if (!canonical && checkSimpleKey()) { -// states.push(new ExpectFlowMappingSimpleValue()); -// expectNode(false, true, true); -// } else { -// writeIndicator("?", true, false, false); -// states.push(new ExpectFlowMappingValue()); -// expectNode(false, true, false); -// } -// } -// } -// } -// -// private class ExpectFlowMappingSimpleValue implements EmitterState { -// public void expect() throws IOException { -// writeIndicator(":", false, false, false); -// states.push(new ExpectFlowMappingKey()); -// expectNode(false, true, false); -// } -// } -// -// private class ExpectFlowMappingValue implements EmitterState { -// public void expect() throws IOException { -// if (canonical || (column > bestWidth) || prettyFlow) { -// writeIndent(); -// } -// writeIndicator(":", true, false, false); -// states.push(new ExpectFlowMappingKey()); -// expectNode(false, true, false); -// } -// } -// -// private class ExpectFirstBlockSequenceItem implements EmitterState { -// public void expect() throws IOException { -// new ExpectBlockSequenceItem(true).expect(); -// } -// } -// -// private class ExpectBlockSequenceItem implements EmitterState { -// private final boolean first; -// -// public ExpectBlockSequenceItem(boolean first) { -// this.first = first; -// } -// -// public void expect() throws IOException { -// if (!this.first && event instanceof SequenceEndEvent) { -// indent = indents.pop(); -// state = states.pop(); -// } else { -// writeIndent(); -// writeWhitespace(indicatorIndent); -// writeIndicator("-", true, false, true); -// states.push(new ExpectBlockSequenceItem(false)); -// expectNode(false, false, false); -// } -// } -// } -// -// private class ExpectFirstBlockMappingKey implements EmitterState { -// public void expect() throws IOException { -// new ExpectBlockMappingKey(true).expect(); -// } -// } -// -// private class ExpectBlockMappingKey implements EmitterState { -// private final boolean first; -// -// public ExpectBlockMappingKey(boolean first) { -// this.first = first; -// } -// -// public void expect() throws IOException { -// if (!this.first && event instanceof MappingEndEvent) { -// indent = indents.pop(); -// state = states.pop(); -// } else { -// writeIndent(); -// if (checkSimpleKey()) { -// states.push(new ExpectBlockMappingSimpleValue()); -// expectNode(false, true, true); -// } else { -// writeIndicator("?", true, false, true); -// states.push(new ExpectBlockMappingValue()); -// expectNode(false, true, false); -// } -// } -// } -// } -// -// private class ExpectBlockMappingSimpleValue implements EmitterState { -// public void expect() throws IOException { -// writeIndicator(":", false, false, false); -// states.push(new ExpectBlockMappingKey(false)); -// expectNode(false, true, false); -// } -// } -// -// private class ExpectBlockMappingValue implements EmitterState { -// public void expect() throws IOException { -// writeIndent(); -// writeIndicator(":", true, false, true); -// states.push(new ExpectBlockMappingKey(false)); -// expectNode(false, true, false); -// } -// } -//} \ No newline at end of file diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYaml.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYaml.java deleted file mode 100644 index 7b6e599..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYaml.java +++ /dev/null @@ -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 list = new ArrayList<>(1); -// list.add(data); -// return this.dumpAll(list.iterator()); -// } -// -// @Override -// public void dump(Object data, Writer output) { -// List 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); -// } -// } -//} \ No newline at end of file diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYamlConfiguration.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYamlConfiguration.java deleted file mode 100644 index f430803..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentedYamlConfiguration.java +++ /dev/null @@ -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; -// } -//} \ No newline at end of file diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentsProvider.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentsProvider.java deleted file mode 100644 index ddc1d8f..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/CommentsProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package cc.carm.lib.configuration.bukkit.commented; - -import java.util.function.Function; - - -public interface CommentsProvider extends Function { -} \ No newline at end of file diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/ConfigComments.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/ConfigComments.java deleted file mode 100644 index d1700ef..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/commented/ConfigComments.java +++ /dev/null @@ -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 comments = new HashMap<>(); - - protected Map 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); - } - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/ItemConfig.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/ItemConfig.java deleted file mode 100644 index e70a8d4..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/ItemConfig.java +++ /dev/null @@ -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 lore; - @NotNull Map> additional; - - public ItemConfig(@NotNull Material type, @Nullable String name, - @Nullable List lore, @NotNull Map> 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 getLore() { - return lore; - } - - public @NotNull Map> getAdditionalLore() { - return additional; - } - - - - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/MessageConfig.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/MessageConfig.java deleted file mode 100644 index 03165bf..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/MessageConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -package cc.carm.lib.configuration.bukkit.data; - -public class MessageConfig { - - - - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitSectionWrapper.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitSectionWrapper.java deleted file mode 100644 index cf95545..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitSectionWrapper.java +++ /dev/null @@ -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; - } - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredItem.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredItem.java deleted file mode 100644 index 42cb203..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredItem.java +++ /dev/null @@ -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 { - - public ConfiguredItem(@Nullable ConfigurationProvider provider, - @Nullable String sectionPath, @NotNull String[] comments, - @NotNull Class valueClass, @Nullable ItemConfig defaultValue, - @NotNull ConfigValueParser parser, - @NotNull ConfigDataFunction> serializer) { - super(provider, sectionPath, comments, valueClass, defaultValue, parser, serializer); - } - -} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredMessage.java b/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredMessage.java deleted file mode 100644 index f86fdae..0000000 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredMessage.java +++ /dev/null @@ -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 { - - - 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) { - - } -} diff --git a/bukkit/pom.xml b/bukkit/pom.xml new file mode 100644 index 0000000..fd1db25 --- /dev/null +++ b/bukkit/pom.xml @@ -0,0 +1,64 @@ + + + + mineconfiguration-parent + cc.carm.lib + 1.0.0 + + 4.0.0 + + ${java.version} + ${java.version} + + mineconfiguration-bukkit + jar + + + + + ${project.parent.groupId} + easyconfiguration-core + ${easyconfiguration.version} + compile + + + + ${project.parent.groupId} + mineconfiguration-craftbukkit + ${project.parent.version} + compile + + + + org.bukkit + bukkit + 1.8.8-R0.1-SNAPSHOT + provided + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + \ No newline at end of file diff --git a/bukkit/src/main/java/cc/carm/lib/configuration/MineConfiguration.java b/bukkit/src/main/java/cc/carm/lib/configuration/MineConfiguration.java new file mode 100644 index 0000000..7eca805 --- /dev/null +++ b/bukkit/src/main/java/cc/carm/lib/configuration/MineConfiguration.java @@ -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); + } + +} diff --git a/bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java b/bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java new file mode 100644 index 0000000..c42101a --- /dev/null +++ b/bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java @@ -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); + } + + +} diff --git a/bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitYAMLComments.java b/bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitYAMLComments.java new file mode 100644 index 0000000..a8bb790 --- /dev/null +++ b/bukkit/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitYAMLComments.java @@ -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 comments = new HashMap<>(); + + protected Map 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()); + } + + +} diff --git a/bungee/pom.xml b/bungee/pom.xml index 1b6fe78..ba0187a 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -3,7 +3,7 @@ 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"> - MineConfiguration + mineconfiguration-parent cc.carm.lib 1.0.0 diff --git a/bungee/src/main/java/cc/carm/lib/configuration/bungee/BungeeConfigProvider.java b/bungee/src/main/java/cc/carm/lib/configuration/bungee/BungeeConfigProvider.java index e353081..32007a2 100644 --- a/bungee/src/main/java/cc/carm/lib/configuration/bungee/BungeeConfigProvider.java +++ b/bungee/src/main/java/cc/carm/lib/configuration/bungee/BungeeConfigProvider.java @@ -1,6 +1,7 @@ package cc.carm.lib.configuration.bungee; 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 net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; @@ -42,14 +43,13 @@ public class BungeeConfigProvider extends FileConfigProvider - MineConfiguration + mineconfiguration-parent cc.carm.lib 1.0.0 - ../../pom.xml 4.0.0 ${java.version} ${java.version} - mineconfiguration-bukkit-common + mineconfiguration-craftbukkit jar @@ -26,8 +25,8 @@ - org.spigotmc - spigot-api + org.bukkit + bukkit 1.8.8-R0.1-SNAPSHOT provided diff --git a/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/CraftConfigValue.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/CraftConfigValue.java new file mode 100644 index 0000000..7dbea23 --- /dev/null +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/CraftConfigValue.java @@ -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 extends CachedConfigValue { + + 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(); + } + +} diff --git a/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/AbstractCraftBuilder.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/AbstractCraftBuilder.java new file mode 100644 index 0000000..7f12588 --- /dev/null +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/AbstractCraftBuilder.java @@ -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> + extends AbstractConfigBuilder { + + public AbstractCraftBuilder() { + super(CraftConfigProvider.class); + } + +} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/BukkitConfigBuilder.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/CraftConfigBuilder.java similarity index 64% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/BukkitConfigBuilder.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/CraftConfigBuilder.java index 555e6e1..e7c6017 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/BukkitConfigBuilder.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/CraftConfigBuilder.java @@ -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.bukkit.builder.sound.SoundConfigBuilder; +import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder; +import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder; import cc.carm.lib.configuration.core.builder.ConfigBuilder; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.jetbrains.annotations.NotNull; -public class BukkitConfigBuilder extends ConfigBuilder { +public class CraftConfigBuilder extends ConfigBuilder { public @NotNull SoundConfigBuilder createSound() { return new SoundConfigBuilder(); diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/serializable/SerializableBuilder.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/serializable/SerializableBuilder.java similarity index 64% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/serializable/SerializableBuilder.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/serializable/SerializableBuilder.java index 8ec3f5a..2cd7cb9 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/serializable/SerializableBuilder.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/serializable/SerializableBuilder.java @@ -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.bukkit.value.ConfiguredSerializable; +import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder; +import cc.carm.lib.configuration.craft.value.ConfiguredSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.jetbrains.annotations.NotNull; public class SerializableBuilder - extends AbstractBukkitBuilder> { + extends AbstractCraftBuilder> { protected final @NotNull Class valueClass; @@ -21,7 +21,7 @@ public class SerializableBuilder @Override public @NotNull ConfiguredSerializable 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); } } diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/sound/SoundConfigBuilder.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/sound/SoundConfigBuilder.java similarity index 60% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/sound/SoundConfigBuilder.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/sound/SoundConfigBuilder.java index b14023d..c504a96 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/builder/sound/SoundConfigBuilder.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/builder/sound/SoundConfigBuilder.java @@ -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.bukkit.data.SoundConfig; -import cc.carm.lib.configuration.bukkit.value.ConfiguredSound; +import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder; +import cc.carm.lib.configuration.craft.data.SoundConfig; +import cc.carm.lib.configuration.craft.value.ConfiguredSound; import org.bukkit.Sound; import org.jetbrains.annotations.NotNull; -public class SoundConfigBuilder extends AbstractBukkitBuilder { +public class SoundConfigBuilder extends AbstractCraftBuilder { public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume, float pitch) { @@ -28,7 +28,7 @@ public class SoundConfigBuilder extends AbstractBukkitBuilder lore; + @NotNull Map> additional; + + public ItemConfig(@NotNull Material type, short damage, + @Nullable String name, @NotNull List lore, + @NotNull Map> 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 getLore() { + return lore; + } + + public @NotNull Map> 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 finalLore = new ArrayList<>(); + if (!this.lore.isEmpty()) finalLore.addAll(this.lore); + + for (String s : withAdditional) { + List 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 serialize() { + Map 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 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> readAdditionalLore(@Nullable ConfigurationWrapper loreSection) { + Map> additionalMap = new HashMap<>(); + if (loreSection == null) return additionalMap; + + for (String loreName : loreSection.getKeys(false)) { + if (!loreSection.isList(loreName)) continue; + + List additionalLore = parseStringList(loreSection.getList(loreName)); + if (additionalLore.isEmpty()) continue; + + additionalMap.put(loreName, additionalLore); + } + + return additionalMap; + } + + +} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/SoundConfig.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/data/SoundConfig.java similarity index 70% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/SoundConfig.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/data/SoundConfig.java index f5f9e28..98c6c8b 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/data/SoundConfig.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/data/SoundConfig.java @@ -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.Sound; @@ -9,19 +9,19 @@ import org.jetbrains.annotations.Nullable; public class SoundConfig { - protected Sound type; + protected @NotNull Sound type; protected float volume; protected float pitch; - public SoundConfig(Sound type) { + public SoundConfig(@NotNull Sound type) { this(type, 1, 1); } - public SoundConfig(Sound type, float volume) { + public SoundConfig(@NotNull Sound type, float volume) { 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.volume = volume; this.pitch = pitch; @@ -35,6 +35,30 @@ public class SoundConfig { 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() { if (pitch != 1) { return type.name() + ":" + volume + ":" + pitch; diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftConfigProvider.java similarity index 51% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftConfigProvider.java index d7d196b..b98d27d 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/source/BukkitConfigProvider.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftConfigProvider.java @@ -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.source.impl.FileConfigProvider; @@ -7,20 +7,23 @@ import org.jetbrains.annotations.NotNull; import java.io.File; -public abstract class BukkitConfigProvider - extends FileConfigProvider { +public abstract class CraftConfigProvider extends FileConfigProvider { - protected ConfigInitializer> initializer; - protected C configuration; + public static final char SEPARATOR = '.'; - public BukkitConfigProvider(@NotNull File file) { + protected ConfigInitializer initializer; + protected YamlConfiguration configuration; + + public CraftConfigProvider(@NotNull File file) { super(file); } public abstract void initializeConfig(); @Override - public abstract @NotNull W getConfiguration(); + public @NotNull CraftSectionWrapper getConfiguration() { + return CraftSectionWrapper.of(this.configuration); + } @Override public void reload() throws Exception { @@ -33,7 +36,7 @@ public abstract class BukkitConfigProvider> getInitializer() { + public @NotNull ConfigInitializer getInitializer() { return this.initializer; } diff --git a/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftSectionWrapper.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftSectionWrapper.java new file mode 100644 index 0000000..993878c --- /dev/null +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/source/CraftSectionWrapper.java @@ -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 getKeys(boolean deep) { + return this.section.getKeys(deep); + } + + @Override + public @NotNull Map 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); + } +} diff --git a/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredItem.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredItem.java new file mode 100644 index 0000000..b675afb --- /dev/null +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredItem.java @@ -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 { + + 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 getItemParser() { + return (s, d) -> ItemConfig.deserialize(s); + } + +} diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredSerializable.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredSerializable.java similarity index 82% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredSerializable.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredSerializable.java index ff8a7ee..bf5ebed 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredSerializable.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredSerializable.java @@ -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.bukkit.source.BukkitConfigProvider; +import cc.carm.lib.configuration.craft.CraftConfigValue; +import cc.carm.lib.configuration.craft.source.CraftConfigProvider; +import cc.carm.lib.configuration.core.source.ConfigCommentInfo; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Optional; -public class ConfiguredSerializable extends BukkitConfigValue { +public class ConfiguredSerializable extends CraftConfigValue { public static ConfiguredSerializable of(@NotNull Class valueClass) { return of(valueClass, null); @@ -21,8 +22,8 @@ public class ConfiguredSerializable extends protected final @NotNull Class valueClass; - public ConfiguredSerializable(@Nullable BukkitConfigProvider provider, - @Nullable String configPath, @NotNull String[] comments, + public ConfiguredSerializable(@Nullable CraftConfigProvider provider, + @Nullable String configPath, @Nullable ConfigCommentInfo comments, @NotNull Class valueClass, @Nullable T defaultValue) { super(provider, configPath, comments, defaultValue); this.valueClass = valueClass; diff --git a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredSound.java b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredSound.java similarity index 59% rename from bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredSound.java rename to craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredSound.java index c51836a..cfb17f8 100644 --- a/bukkit/common/src/main/java/cc/carm/lib/configuration/bukkit/value/ConfiguredSound.java +++ b/craftbukkit/src/main/java/cc/carm/lib/configuration/craft/value/ConfiguredSound.java @@ -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.source.ConfigCommentInfo; import cc.carm.lib.configuration.core.source.ConfigurationProvider; 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.entity.Player; import org.jetbrains.annotations.NotNull; @@ -15,24 +16,35 @@ import java.util.Optional; public class ConfiguredSound extends ConfiguredValue { 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) { - 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) { - return BukkitConfigValue.builder().createSound().defaults(sound, volume, pitch).build(); + return CraftConfigValue.builder().createSound().defaults(sound, volume, pitch).build(); } - public ConfiguredSound(@Nullable ConfigurationProvider provider, - @Nullable String sectionPath, @NotNull String[] comments, + @Nullable String sectionPath, @Nullable ConfigCommentInfo comments, @Nullable SoundConfig defaultValue) { 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) { Optional.ofNullable(get()).ifPresent(c -> c.playTo(player)); } diff --git a/pom.xml b/pom.xml index d9b3db7..286e1a9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,10 @@ 4.0.0 bungee - bukkit/common + + craftbukkit + bukkit + spigot 1.8 @@ -14,10 +17,10 @@ UTF-8 UTF-8 - 1.1.0 + 2.3.0 cc.carm.lib - MineConfiguration + mineconfiguration-parent 1.0.0 pom diff --git a/spigot/pom.xml b/spigot/pom.xml new file mode 100644 index 0000000..bd683ff --- /dev/null +++ b/spigot/pom.xml @@ -0,0 +1,65 @@ + + + + mineconfiguration-parent + cc.carm.lib + 1.0.0 + + 4.0.0 + + ${java.version} + ${java.version} + + minecronfiguration-spigot + jar + + + + + ${project.parent.groupId} + easyconfiguration-core + ${easyconfiguration.version} + compile + + + + ${project.parent.groupId} + mineconfiguration-craftbukkit + ${project.parent.version} + compile + + + + org.spigotmc + spigot-api + 1.18.2-R0.1-SNAPSHOT + provided + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + + \ No newline at end of file diff --git a/spigot/src/main/java/cc/carm/lib/configuration/MineConfiguration.java b/spigot/src/main/java/cc/carm/lib/configuration/MineConfiguration.java new file mode 100644 index 0000000..0ae3863 --- /dev/null +++ b/spigot/src/main/java/cc/carm/lib/configuration/MineConfiguration.java @@ -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); + } + +} diff --git a/spigot/src/main/java/cc/carm/lib/configuration/spigot/source/SpigotConfigProvider.java b/spigot/src/main/java/cc/carm/lib/configuration/spigot/source/SpigotConfigProvider.java new file mode 100644 index 0000000..b19c2fd --- /dev/null +++ b/spigot/src/main/java/cc/carm/lib/configuration/spigot/source/SpigotConfigProvider.java @@ -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 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; + } + +}