Archive eaglerxpaper (plugin, 1.8.8 - 26.x, clean)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.velocity.nightconfig)
|
||||
compileOnly(libs.snakeyaml)
|
||||
compileOnly(libs.gson)
|
||||
compileOnly(libs.guava)
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.gson.GSONConfigLoader;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigLoader;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.YAMLConfigLoader;
|
||||
|
||||
public enum EnumConfigFormat {
|
||||
|
||||
YAML(ImmutableSet.of("yml", "yaml"), "yml", (f) -> {
|
||||
return YAMLConfigLoader.getConfigFile(f);
|
||||
}, "org.yaml.snakeyaml.Yaml"),
|
||||
|
||||
TOML(ImmutableSet.of("toml"), "toml", (f) -> {
|
||||
return NightConfigLoader.getConfigFile(f);
|
||||
}, "com.electronwill.nightconfig.toml.TomlParser"),
|
||||
|
||||
JSON(ImmutableSet.of("json"), "json", (f) -> {
|
||||
return GSONConfigLoader.getConfigFile(f);
|
||||
}, "com.google.gson.Gson");
|
||||
|
||||
private interface IConfigProvider {
|
||||
IEaglerConfig load(File file) throws IOException;
|
||||
}
|
||||
|
||||
private final Set<String> exts;
|
||||
private final String defaultExt;
|
||||
private final IConfigProvider provider;
|
||||
private final String depends;
|
||||
private int supported;
|
||||
|
||||
private EnumConfigFormat(Set<String> exts, String defaultExt, IConfigProvider provider, String depends) {
|
||||
this.exts = exts;
|
||||
this.defaultExt = defaultExt;
|
||||
this.provider = provider;
|
||||
this.depends = depends;
|
||||
}
|
||||
|
||||
public Set<String> getExts() {
|
||||
return exts;
|
||||
}
|
||||
|
||||
public String getDefaultExt() {
|
||||
return defaultExt;
|
||||
}
|
||||
|
||||
public IEaglerConfig getConfigFile(File file) throws IOException {
|
||||
return provider.load(file);
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
if (supported == 0) {
|
||||
supported = classAvailable(depends) ? 2 : 1;
|
||||
}
|
||||
return supported == 2;
|
||||
}
|
||||
|
||||
public static Set<EnumConfigFormat> getSupported() {
|
||||
Set<EnumConfigFormat> ret = EnumSet.noneOf(EnumConfigFormat.class);
|
||||
for (EnumConfigFormat fmt : values()) {
|
||||
if (fmt.isSupported()) {
|
||||
ret.add(fmt);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static boolean classAvailable(String name) {
|
||||
try {
|
||||
Class.forName(name);
|
||||
return true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface IEaglerConfList {
|
||||
|
||||
boolean exists();
|
||||
|
||||
boolean initialized();
|
||||
|
||||
void setComment(String comment);
|
||||
|
||||
IEaglerConfSection appendSection();
|
||||
|
||||
IEaglerConfList appendList();
|
||||
|
||||
void appendInteger(int value);
|
||||
|
||||
default void appendIntegers(List<Integer> lst) {
|
||||
lst.forEach((i) -> this.appendInteger(i));
|
||||
}
|
||||
|
||||
void appendString(String string);
|
||||
|
||||
default void appendStrings(List<String> lst) {
|
||||
lst.forEach(this::appendString);
|
||||
}
|
||||
|
||||
int getLength();
|
||||
|
||||
IEaglerConfSection getIfSection(int index);
|
||||
|
||||
IEaglerConfList getIfList(int index);
|
||||
|
||||
boolean isInteger(int index);
|
||||
|
||||
int getIfInteger(int index, int defaultVal);
|
||||
|
||||
default int getIfInteger(int index) {
|
||||
return getIfInteger(index, -1);
|
||||
}
|
||||
|
||||
boolean isString(int index);
|
||||
|
||||
String getIfString(int index, String defaultVal);
|
||||
|
||||
default String getIfString(int index) {
|
||||
return getIfString(index, null);
|
||||
}
|
||||
|
||||
default List<Integer> getAsIntegerList() {
|
||||
int len = getLength();
|
||||
List<Integer> ret = new ArrayList<>(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (isInteger(i)) {
|
||||
ret.add(getIfInteger(i));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
default List<Integer> getAsIntegerList(Supplier<List<Integer>> defaultContents) {
|
||||
if (!initialized()) {
|
||||
appendIntegers(defaultContents.get());
|
||||
}
|
||||
return getAsIntegerList();
|
||||
}
|
||||
|
||||
default List<Integer> getAsIntegerList(Supplier<List<Integer>> defaultContents, String comment) {
|
||||
if (!initialized()) {
|
||||
setComment(comment);
|
||||
appendIntegers(defaultContents.get());
|
||||
}
|
||||
return getAsIntegerList();
|
||||
}
|
||||
|
||||
default List<String> getAsStringList() {
|
||||
int len = getLength();
|
||||
List<String> ret = new ArrayList<>(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String str = getIfString(i);
|
||||
if (str != null) {
|
||||
ret.add(str);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
default List<String> getAsStringList(Supplier<List<String>> defaultContents) {
|
||||
if (!initialized()) {
|
||||
appendStrings(defaultContents.get());
|
||||
}
|
||||
return getAsStringList();
|
||||
}
|
||||
|
||||
default List<String> getAsStringList(Supplier<List<String>> defaultContents, String comment) {
|
||||
if (!initialized()) {
|
||||
setComment(comment);
|
||||
appendStrings(defaultContents.get());
|
||||
}
|
||||
return getAsStringList();
|
||||
}
|
||||
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface IEaglerConfSection {
|
||||
|
||||
boolean exists();
|
||||
|
||||
boolean initialized();
|
||||
|
||||
void setComment(String comment);
|
||||
|
||||
IEaglerConfSection getIfSection(String name);
|
||||
|
||||
IEaglerConfSection getSection(String name);
|
||||
|
||||
IEaglerConfList getIfList(String name);
|
||||
|
||||
IEaglerConfList getList(String name);
|
||||
|
||||
List<String> getKeys();
|
||||
|
||||
boolean isBoolean(String name);
|
||||
|
||||
boolean getBoolean(String name);
|
||||
|
||||
boolean getBoolean(String name, boolean defaultValue, String comment);
|
||||
|
||||
default boolean getBoolean(String name, boolean defaultValue) {
|
||||
return getBoolean(name, defaultValue, null);
|
||||
}
|
||||
|
||||
boolean getBoolean(String name, Supplier<Boolean> defaultValue, String comment);
|
||||
|
||||
default boolean getBoolean(String name, Supplier<Boolean> defaultValue) {
|
||||
return getBoolean(name, defaultValue, null);
|
||||
}
|
||||
|
||||
boolean isInteger(String name);
|
||||
|
||||
int getInteger(String name, int defaultValue, String comment);
|
||||
|
||||
default int getInteger(String name, int defaultValue) {
|
||||
return getInteger(name, defaultValue, null);
|
||||
}
|
||||
|
||||
int getInteger(String name, Supplier<Integer> defaultValue, String comment);
|
||||
|
||||
default int getInteger(String name, Supplier<Integer> defaultValue) {
|
||||
return getInteger(name, defaultValue, null);
|
||||
}
|
||||
|
||||
boolean isString(String name);
|
||||
|
||||
String getIfString(String name);
|
||||
|
||||
String getString(String name, String defaultValue, String comment);
|
||||
|
||||
default String getString(String name, String defaultValue) {
|
||||
return getString(name, defaultValue, null);
|
||||
}
|
||||
|
||||
String getString(String name, Supplier<String> defaultValue, String comment);
|
||||
|
||||
default String getString(String name, Supplier<String> defaultValue) {
|
||||
return getString(name, defaultValue, null);
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IEaglerConfig {
|
||||
|
||||
EnumConfigFormat getFormat();
|
||||
|
||||
IEaglerConfSection getRoot();
|
||||
|
||||
boolean isModified();
|
||||
|
||||
boolean saveIfModified() throws IOException;
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2026 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface IRandomSupplier<T> extends Supplier<T> {
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class ReflectUtil {
|
||||
public static RuntimeException propagateReflectThrowable(Exception ex) {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
InvocationTargetException exx = (InvocationTargetException)ex;
|
||||
Throwable cause = exx.getCause();
|
||||
if (cause != null) {
|
||||
if (cause instanceof RuntimeException) {
|
||||
RuntimeException cause2 = (RuntimeException)cause;
|
||||
return cause2;
|
||||
}
|
||||
return new RuntimeException("Encountered an InvocationTargetException while performing reflection", cause);
|
||||
}
|
||||
} else if (ex instanceof RuntimeException) {
|
||||
RuntimeException exx = (RuntimeException)ex;
|
||||
return exx;
|
||||
}
|
||||
return new RuntimeException("Could not perform reflection!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class WrapUtil {
|
||||
|
||||
// From an old version of apache commons lang3
|
||||
public static String wrap(final String str, int wrapLength, String newLineStr, final boolean wrapLongWords,
|
||||
String wrapOn) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
if (newLineStr == null) {
|
||||
newLineStr = System.lineSeparator();
|
||||
}
|
||||
if (wrapLength < 1) {
|
||||
wrapLength = 1;
|
||||
}
|
||||
final Pattern patternToWrapOn = Pattern.compile(wrapOn);
|
||||
final int inputLineLength = str.length();
|
||||
int offset = 0;
|
||||
final StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
|
||||
|
||||
while (offset < inputLineLength) {
|
||||
int spaceToWrapAt = -1;
|
||||
Matcher matcher = patternToWrapOn.matcher(str.substring(offset,
|
||||
Math.min((int) Math.min(Integer.MAX_VALUE, offset + wrapLength + 1L), inputLineLength)));
|
||||
if (matcher.find()) {
|
||||
if (matcher.start() == 0) {
|
||||
offset += matcher.end();
|
||||
continue;
|
||||
}
|
||||
spaceToWrapAt = matcher.start() + offset;
|
||||
}
|
||||
|
||||
// only last line without leading spaces is left
|
||||
if (inputLineLength - offset <= wrapLength) {
|
||||
break;
|
||||
}
|
||||
|
||||
while (matcher.find()) {
|
||||
spaceToWrapAt = matcher.start() + offset;
|
||||
}
|
||||
|
||||
if (spaceToWrapAt >= offset) {
|
||||
// normal case
|
||||
wrappedLine.append(str, offset, spaceToWrapAt);
|
||||
wrappedLine.append(newLineStr);
|
||||
offset = spaceToWrapAt + 1;
|
||||
|
||||
} else // really long word or URL
|
||||
if (wrapLongWords) {
|
||||
// wrap really long word one line at a time
|
||||
wrappedLine.append(str, offset, wrapLength + offset);
|
||||
wrappedLine.append(newLineStr);
|
||||
offset += wrapLength;
|
||||
} else {
|
||||
// do not wrap really long word, just extend beyond limit
|
||||
matcher = patternToWrapOn.matcher(str.substring(offset + wrapLength));
|
||||
if (matcher.find()) {
|
||||
spaceToWrapAt = matcher.start() + offset + wrapLength;
|
||||
}
|
||||
|
||||
if (spaceToWrapAt >= 0) {
|
||||
wrappedLine.append(str, offset, spaceToWrapAt);
|
||||
wrappedLine.append(newLineStr);
|
||||
offset = spaceToWrapAt + 1;
|
||||
} else {
|
||||
wrappedLine.append(str, offset, str.length());
|
||||
offset = inputLineLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Whatever is left in line is short enough to just pass through
|
||||
wrappedLine.append(str, offset, str.length());
|
||||
|
||||
return wrappedLine.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2026 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.docsutil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
|
||||
public class DocsDirectory {
|
||||
|
||||
final Map<String, DocsSection> map = new HashMap<>();
|
||||
|
||||
DocsDirectory() {
|
||||
}
|
||||
|
||||
public <T> T addFile(String name, IDocConfLoader<T> provider) throws IOException {
|
||||
DocsSection section = map.get(name);
|
||||
if (section == null) {
|
||||
map.put(name, section = new DocsSection());
|
||||
}
|
||||
return provider.call(section);
|
||||
}
|
||||
|
||||
public interface IDocConfLoader<T> {
|
||||
T call(IEaglerConfSection section) throws IOException;
|
||||
}
|
||||
|
||||
}
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.docsutil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsDirectory;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsValue;
|
||||
|
||||
public class DocsGenerator {
|
||||
private final String title;
|
||||
private final String desc;
|
||||
private final Map<String, DocsDirectory> map = new HashMap<String, DocsDirectory>();
|
||||
private String primaryFile;
|
||||
|
||||
public DocsGenerator(String title, String desc) {
|
||||
this.title = title;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public void addPlatform(String platform, IDocDirLoader provider) throws IOException {
|
||||
DocsDirectory directory = this.map.get(platform);
|
||||
if (directory == null) {
|
||||
directory = new DocsDirectory();
|
||||
this.map.put(platform, directory);
|
||||
}
|
||||
provider.call(directory);
|
||||
}
|
||||
|
||||
private static void flatten(Map<String, Header> headers, Map<String, Content> content, String platf, String pfx, String title, DocsSection section) {
|
||||
for (Map.Entry<String, Object> etr : section.entries.entrySet()) {
|
||||
Object v;
|
||||
if (etr.getValue() instanceof DocsValue) {
|
||||
v = (DocsValue)etr.getValue();
|
||||
DocsGenerator.flatten(content, platf, pfx + etr.getKey(), title + "`" + etr.getKey() + "`", (DocsValue)v);
|
||||
continue;
|
||||
}
|
||||
if (etr.getValue() instanceof DocsSection) {
|
||||
v = (DocsSection)etr.getValue();
|
||||
Header headerObj = new Header(title + "`" + etr.getKey() + "`");
|
||||
headerObj.platforms.add(platf);
|
||||
if (((DocsSection)v).comment != null && !((DocsSection)v).comment.isEmpty()) {
|
||||
Summary summaryObj = new Summary(((DocsSection)v).comment);
|
||||
summaryObj.platforms.add(platf);
|
||||
headerObj.summary.add(summaryObj);
|
||||
}
|
||||
DocsGenerator.merge(headers, pfx + etr.getKey(), headerObj);
|
||||
DocsGenerator.flatten(headers, content, platf, pfx + etr.getKey() + ":", title + "`" + etr.getKey() + "` : ", (DocsSection)v);
|
||||
continue;
|
||||
}
|
||||
if (etr.getValue() instanceof DocsList) {
|
||||
v = (DocsList)etr.getValue();
|
||||
DocsGenerator.flatten(headers, content, platf, pfx + etr.getKey(), title + "`" + etr.getKey() + "`", (DocsList)v);
|
||||
continue;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void flatten(Map<String, Header> headers, Map<String, Content> content, String platf, String pfx, String title, DocsList section) {
|
||||
boolean hasHeader = false;
|
||||
ArrayList<String> values = new ArrayList<String>();
|
||||
for (Object etr : section.entries) {
|
||||
String t2;
|
||||
int idx;
|
||||
Object v;
|
||||
if (etr instanceof DocsValue) {
|
||||
v = (DocsValue)etr;
|
||||
values.add(((DocsValue)v).value == null ? "null" : (((DocsValue)v).type != DocsValue.Type.STR ? ((DocsValue)v).value : "\"" + ((DocsValue)v).value.replace("\\", "\\\\").replace("\"", "\\\"") + "\""));
|
||||
continue;
|
||||
}
|
||||
if (etr instanceof DocsSection) {
|
||||
v = (DocsSection)etr;
|
||||
idx = title.lastIndexOf(": ");
|
||||
if (idx == -1) {
|
||||
idx = title.lastIndexOf("> ") + 3;
|
||||
}
|
||||
t2 = title.substring(0, idx + 2) + "[" + title.substring(idx + 2) + "]";
|
||||
DocsGenerator.flatten(headers, content, platf, pfx + ":{}:", t2 + " : ", (DocsSection)v);
|
||||
hasHeader = true;
|
||||
continue;
|
||||
}
|
||||
if (etr instanceof DocsList) {
|
||||
v = (DocsList)etr;
|
||||
idx = title.lastIndexOf(": ");
|
||||
if (idx == -1) {
|
||||
idx = title.lastIndexOf("> ") + 3;
|
||||
}
|
||||
t2 = title.substring(0, idx + 2) + "[" + title.substring(idx + 2) + "]";
|
||||
DocsGenerator.flatten(headers, content, platf, pfx + ":[]:", t2, (DocsList)v);
|
||||
hasHeader = true;
|
||||
continue;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (hasHeader) {
|
||||
int idx = title.lastIndexOf(": ");
|
||||
if (idx == -1) {
|
||||
idx = title.lastIndexOf("> ") + 3;
|
||||
}
|
||||
String t2 = title.substring(0, idx + 2) + "[" + title.substring(idx + 2) + "]";
|
||||
Header headerObj = new Header(t2);
|
||||
headerObj.platforms.add(platf);
|
||||
if (section.comment != null && !section.comment.isEmpty()) {
|
||||
Summary summaryObj = new Summary(section.comment);
|
||||
summaryObj.platforms.add(platf);
|
||||
headerObj.summary.add(summaryObj);
|
||||
}
|
||||
DocsGenerator.merge(headers, pfx, headerObj);
|
||||
} else {
|
||||
Content contentObj = new Content(title);
|
||||
contentObj.platforms.add(platf);
|
||||
if (section.comment != null && !section.comment.isEmpty()) {
|
||||
Summary summaryObj = new Summary(section.comment);
|
||||
summaryObj.platforms.add(platf);
|
||||
contentObj.summary.add(summaryObj);
|
||||
}
|
||||
Defaults defaultsObj = new Defaults("[ " + String.join((CharSequence)", ", values) + " ]");
|
||||
defaultsObj.platforms.add(platf);
|
||||
contentObj.defaults.add(defaultsObj);
|
||||
DocsGenerator.merge(content, pfx, contentObj);
|
||||
}
|
||||
}
|
||||
|
||||
private static void flatten(Map<String, Content> content, String platf, String pfx, String title, DocsValue value) {
|
||||
Content contentObj = new Content(title);
|
||||
contentObj.platforms.add(platf);
|
||||
if (value.comment != null && !value.comment.isEmpty()) {
|
||||
Summary summaryObj = new Summary(value.comment);
|
||||
summaryObj.platforms.add(platf);
|
||||
contentObj.summary.add(summaryObj);
|
||||
}
|
||||
if (!value.randomized) {
|
||||
Defaults defaultsObj = new Defaults(value.value == null ? "null" : (value.type != DocsValue.Type.STR ? value.value : "\"" + value.value.replace("\\", "\\\\").replace("\"", "\\\"") + "\""));
|
||||
defaultsObj.platforms.add(platf);
|
||||
contentObj.defaults.add(defaultsObj);
|
||||
}
|
||||
DocsGenerator.merge(content, pfx, contentObj);
|
||||
}
|
||||
|
||||
private static void merge(Map<String, Header> headers, String pfx, Header item) {
|
||||
Header existing = headers.get(pfx);
|
||||
if (existing == null) {
|
||||
headers.put(pfx, item);
|
||||
return;
|
||||
}
|
||||
for (String str : item.platforms) {
|
||||
if (existing.platforms.contains(str)) continue;
|
||||
existing.platforms.add(str);
|
||||
}
|
||||
block1: for (Summary str1 : item.summary) {
|
||||
for (Summary str2 : existing.summary) {
|
||||
if (!str1.summary.equals(str2.summary)) continue;
|
||||
for (String str : str1.platforms) {
|
||||
if (str2.platforms.contains(str)) continue;
|
||||
str2.platforms.add(str);
|
||||
}
|
||||
continue block1;
|
||||
}
|
||||
existing.summary.add((Summary)str1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void merge(Map<String, Content> content, String id, Content item) {
|
||||
Content existing = content.get(id);
|
||||
if (existing == null) {
|
||||
content.put(id, item);
|
||||
return;
|
||||
}
|
||||
for (String str : item.platforms) {
|
||||
if (existing.platforms.contains(str)) continue;
|
||||
existing.platforms.add(str);
|
||||
}
|
||||
block1: for (Object str1 : item.summary) {
|
||||
for (Object str2 : existing.summary) {
|
||||
if (!((Summary)str1).summary.equals(((Summary)str2).summary)) continue;
|
||||
for (String str : ((Summary)str1).platforms) {
|
||||
if (((Summary)str2).platforms.contains(str)) continue;
|
||||
((Summary)str2).platforms.add(str);
|
||||
}
|
||||
continue block1;
|
||||
}
|
||||
existing.summary.add((Summary)str1);
|
||||
}
|
||||
block4: for (Object str1 : item.defaults) {
|
||||
for (Object str2 : existing.defaults) {
|
||||
if (!((Defaults)str1).defaults.equals(((Defaults)str2).defaults)) continue;
|
||||
for (String str : ((Defaults)str1).platforms) {
|
||||
if (((Defaults)str2).platforms.contains(str)) continue;
|
||||
((Defaults)str2).platforms.add(str);
|
||||
}
|
||||
continue block4;
|
||||
}
|
||||
existing.defaults.add((Defaults)str1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - void declaration
|
||||
*/
|
||||
public void writeDocs(PrintWriter writer) {
|
||||
String prefix;
|
||||
String[] descLines;
|
||||
ArrayList<String> sortedPlatforms = new ArrayList<String>(this.map.keySet());
|
||||
Collections.sort(sortedPlatforms);
|
||||
HashMap<String, Header> headers = new HashMap<String, Header>();
|
||||
HashMap<String, Content> sections = new HashMap<String, Content>();
|
||||
for (String platfName : sortedPlatforms) {
|
||||
DocsDirectory platf = this.map.get(platfName);
|
||||
for (Map.Entry<String, DocsSection> entry : platf.map.entrySet()) {
|
||||
DocsGenerator.flatten(headers, sections, platfName, entry.getKey() + ">", "`/" + entry.getKey() + ".cfg` > ", entry.getValue());
|
||||
}
|
||||
}
|
||||
ArrayList<Map.Entry> sortedSections = new ArrayList<Map.Entry>(sections.entrySet());
|
||||
Collections.sort(sortedSections, (Comparator)Map.Entry.comparingByKey());
|
||||
if (this.primaryFile != null) {
|
||||
prefix = this.primaryFile + ">";
|
||||
ArrayList<Map.Entry> tmp = new ArrayList<Map.Entry>(sortedSections.size());
|
||||
for (Map.Entry entry : sortedSections) {
|
||||
if (!((String)entry.getKey()).startsWith(prefix)) continue;
|
||||
tmp.add(entry);
|
||||
}
|
||||
for (Map.Entry entry : sortedSections) {
|
||||
if (((String)entry.getKey()).startsWith(prefix)) continue;
|
||||
tmp.add(entry);
|
||||
}
|
||||
sortedSections = tmp;
|
||||
}
|
||||
writer.println("## " + this.title);
|
||||
descLines = this.desc.split("(\\r\\n|\\r|\\n)");
|
||||
for (int i = 0; i < descLines.length; ++i) {
|
||||
writer.println(descLines[i]);
|
||||
}
|
||||
writer.println();
|
||||
writer.println("*(Placeholder extension \".cfg\" replaced with \".yaml\", \".toml\", or \".gson\")*");
|
||||
String vigg = null;
|
||||
for (Map.Entry entry : sortedSections) {
|
||||
String string = (String)entry.getKey();
|
||||
int idx = string.lastIndexOf(58);
|
||||
if (!(idx == -1 || vigg != null && vigg.length() == idx && vigg.regionMatches(0, string, 0, idx))) {
|
||||
vigg = string.substring(0, idx);
|
||||
idx = -1;
|
||||
while ((idx = string.indexOf(58, idx + 1)) != -1) {
|
||||
Header head = (Header)headers.remove(string.substring(0, idx));
|
||||
if (head == null) continue;
|
||||
writer.println();
|
||||
writer.println("## " + head.title + " <sub>(" + String.join((CharSequence)", ", head.platforms) + ")</sub>");
|
||||
if (head.summary.isEmpty()) continue;
|
||||
writer.println("**Summary:**");
|
||||
for (Summary sum : head.summary) {
|
||||
writer.println("- " + sum.summary + " <sub>(" + String.join((CharSequence)", ", sum.platforms) + ")</sub>");
|
||||
}
|
||||
}
|
||||
}
|
||||
Content sec = (Content)entry.getValue();
|
||||
writer.println();
|
||||
writer.println("## <small>" + sec.title + " <sub>(" + String.join((CharSequence)", ", sec.platforms) + ")</sub></small>");
|
||||
if (!sec.summary.isEmpty()) {
|
||||
writer.println("**Summary:**");
|
||||
for (Summary sum : sec.summary) {
|
||||
writer.println("- " + sum.summary + " <sub>(" + String.join((CharSequence)", ", sum.platforms) + ")</sub>");
|
||||
}
|
||||
}
|
||||
if (sec.defaults.isEmpty()) continue;
|
||||
if (!sec.summary.isEmpty()) {
|
||||
writer.println();
|
||||
}
|
||||
writer.println("**Defaults:**");
|
||||
for (Defaults def : sec.defaults) {
|
||||
writer.println("- `" + def.defaults + "` <sub>(" + String.join((CharSequence)", ", def.platforms) + ")</sub>");
|
||||
}
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
public void setPrimaryFile(String primaryFile) {
|
||||
this.primaryFile = primaryFile;
|
||||
}
|
||||
|
||||
public static interface IDocDirLoader {
|
||||
public void call(DocsDirectory var1) throws IOException;
|
||||
}
|
||||
|
||||
private static class Header {
|
||||
private final String title;
|
||||
private final List<String> platforms;
|
||||
private final List<Summary> summary;
|
||||
|
||||
private Header(String title) {
|
||||
this.title = title;
|
||||
this.platforms = new ArrayList<String>();
|
||||
this.summary = new ArrayList<Summary>();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Summary {
|
||||
private final String summary;
|
||||
private final List<String> platforms;
|
||||
|
||||
private Summary(String summary) {
|
||||
this.summary = summary;
|
||||
this.platforms = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Content {
|
||||
private final String title;
|
||||
private final List<String> platforms;
|
||||
private final List<Summary> summary;
|
||||
private final List<Defaults> defaults;
|
||||
|
||||
private Content(String title) {
|
||||
this.title = title;
|
||||
this.platforms = new ArrayList<String>();
|
||||
this.summary = new ArrayList<Summary>();
|
||||
this.defaults = new ArrayList<Defaults>();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Defaults {
|
||||
private final String defaults;
|
||||
private final List<String> platforms;
|
||||
|
||||
private Defaults(String defaults) {
|
||||
this.defaults = defaults;
|
||||
this.platforms = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.docsutil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsValue;
|
||||
|
||||
class DocsList
|
||||
implements IEaglerConfList {
|
||||
final List<Object> entries = new ArrayList<Object>();
|
||||
private boolean initialized;
|
||||
String comment;
|
||||
|
||||
DocsList() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection appendSection() {
|
||||
DocsSection object = new DocsSection();
|
||||
this.entries.add(object);
|
||||
this.initialized = true;
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList appendList() {
|
||||
DocsList object = new DocsList();
|
||||
this.entries.add(object);
|
||||
this.initialized = true;
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendInteger(int value) {
|
||||
DocsValue object = new DocsValue(DocsValue.Type.INT, Integer.toString(value), null, false);
|
||||
this.entries.add(object);
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendString(String string) {
|
||||
DocsValue object = new DocsValue(DocsValue.Type.STR, string, null, false);
|
||||
this.entries.add(object);
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return this.entries.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(int index) {
|
||||
if (index < 0 || index >= this.entries.size()) {
|
||||
return null;
|
||||
}
|
||||
if (this.entries.get(index) instanceof DocsSection) {
|
||||
DocsSection s = (DocsSection)this.entries.get(index);
|
||||
return s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(int index) {
|
||||
if (index < 0 || index >= this.entries.size()) {
|
||||
return null;
|
||||
}
|
||||
if (this.entries.get(index) instanceof DocsList) {
|
||||
DocsList l = (DocsList)this.entries.get(index);
|
||||
return l;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(int index) {
|
||||
if (index < 0 || index >= this.entries.size()) {
|
||||
return false;
|
||||
}
|
||||
if (this.entries.get(index) instanceof DocsValue) {
|
||||
DocsValue v = (DocsValue)this.entries.get(index);
|
||||
return v.type == DocsValue.Type.INT;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIfInteger(int index, int defaultVal) {
|
||||
if (index < 0 || index >= this.entries.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Object obj = this.entries.get(index);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.INT) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return Integer.parseInt(v.value);
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(int index) {
|
||||
if (index < 0 || index >= this.entries.size()) {
|
||||
return false;
|
||||
}
|
||||
if (this.entries.get(index) instanceof DocsValue) {
|
||||
DocsValue v = (DocsValue)this.entries.get(index);
|
||||
return v.type == DocsValue.Type.STR;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(int index, String defaultVal) {
|
||||
if (index < 0 || index >= this.entries.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Object obj = this.entries.get(index);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.STR) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return v.value;
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.google.common.collect.ImmutableList
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.docsutil;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IRandomSupplier;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.docsutil.DocsValue;
|
||||
|
||||
class DocsSection
|
||||
implements IEaglerConfSection {
|
||||
final Map<String, Object> entries = new HashMap<String, Object>();
|
||||
private boolean initialized;
|
||||
String comment;
|
||||
|
||||
DocsSection() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(String name) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsSection) {
|
||||
DocsSection s = (DocsSection)obj;
|
||||
return s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getSection(String name) {
|
||||
if (this.entries.get(name) instanceof DocsSection) {
|
||||
DocsSection s = (DocsSection)this.entries.get(name);
|
||||
return s;
|
||||
}
|
||||
DocsSection sec = new DocsSection();
|
||||
this.entries.put(name, sec);
|
||||
this.initialized = true;
|
||||
return sec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(String name) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsList) {
|
||||
DocsList l = (DocsList)obj;
|
||||
return l;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getList(String name) {
|
||||
if (this.entries.get(name) instanceof DocsList) {
|
||||
DocsList l = (DocsList)this.entries.get(name);
|
||||
return l;
|
||||
}
|
||||
DocsList lst = new DocsList();
|
||||
this.entries.put(name, lst);
|
||||
this.initialized = true;
|
||||
return lst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getKeys() {
|
||||
return ImmutableList.copyOf(this.entries.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String name) {
|
||||
if (this.entries.get(name) instanceof DocsValue) {
|
||||
DocsValue v = (DocsValue)this.entries.get(name);
|
||||
return v.type == DocsValue.Type.BOOL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.BOOL) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return Boolean.parseBoolean(v.value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, boolean defaultValue, String comment) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.BOOL) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return Boolean.parseBoolean(v.value);
|
||||
}
|
||||
DocsValue val = new DocsValue(DocsValue.Type.BOOL, Boolean.toString(defaultValue), comment, false);
|
||||
this.entries.put(name, val);
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, Supplier<Boolean> defaultValue, String comment) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.BOOL) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return Boolean.parseBoolean(v.value);
|
||||
}
|
||||
boolean def = defaultValue.get();
|
||||
DocsValue val = new DocsValue(DocsValue.Type.BOOL, Boolean.toString(def), comment, defaultValue instanceof IRandomSupplier);
|
||||
this.entries.put(name, val);
|
||||
this.initialized = true;
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(String name) {
|
||||
if (this.entries.get(name) instanceof DocsValue) {
|
||||
DocsValue v = (DocsValue)this.entries.get(name);
|
||||
return v.type == DocsValue.Type.INT;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, int defaultValue, String comment) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.INT) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return Integer.parseInt(v.value);
|
||||
}
|
||||
DocsValue val = new DocsValue(DocsValue.Type.INT, Integer.toString(defaultValue), comment, false);
|
||||
this.entries.put(name, val);
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, Supplier<Integer> defaultValue, String comment) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.INT) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return Integer.parseInt(v.value);
|
||||
}
|
||||
int def = defaultValue.get();
|
||||
DocsValue val = new DocsValue(DocsValue.Type.INT, Integer.toString(def), comment, defaultValue instanceof IRandomSupplier);
|
||||
this.entries.put(name, val);
|
||||
this.initialized = true;
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(String name) {
|
||||
if (this.entries.get(name) instanceof DocsValue) {
|
||||
DocsValue v = (DocsValue)this.entries.get(name);
|
||||
return v.type == DocsValue.Type.STR;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(String name) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.STR) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return v.value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, String defaultValue, String comment) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.STR) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return v.value;
|
||||
}
|
||||
DocsValue val = new DocsValue(DocsValue.Type.STR, defaultValue, comment, false);
|
||||
this.entries.put(name, val);
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, Supplier<String> defaultValue, String comment) {
|
||||
Object obj = this.entries.get(name);
|
||||
if (obj instanceof DocsValue && ((DocsValue)obj).type == DocsValue.Type.STR) {
|
||||
DocsValue v = (DocsValue)obj;
|
||||
return v.value;
|
||||
}
|
||||
String def = defaultValue.get();
|
||||
DocsValue val = new DocsValue(DocsValue.Type.STR, def, comment, defaultValue instanceof IRandomSupplier);
|
||||
this.entries.put(name, val);
|
||||
this.initialized = true;
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2026 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.docsutil;
|
||||
|
||||
class DocsValue {
|
||||
|
||||
static enum Type {
|
||||
BOOL, INT, STR
|
||||
}
|
||||
|
||||
final Type type;
|
||||
final String value;
|
||||
final String comment;
|
||||
final boolean randomized;
|
||||
|
||||
DocsValue(Type type, String value, String comment, boolean randomized) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.comment = comment;
|
||||
this.randomized = randomized;
|
||||
}
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.gson;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.EnumConfigFormat;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
|
||||
public class GSONConfigBase implements IEaglerConfig {
|
||||
|
||||
final File file;
|
||||
GSONConfigSection root;
|
||||
boolean modified;
|
||||
|
||||
GSONConfigBase(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumConfigFormat getFormat() {
|
||||
return EnumConfigFormat.JSON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveIfModified() throws IOException {
|
||||
if (modified) {
|
||||
GSONConfigLoader.writeConfigFile(root.json, file);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.gson;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
|
||||
public class GSONConfigList implements IEaglerConfList {
|
||||
|
||||
private final GSONConfigBase owner;
|
||||
final JsonArray json;
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
public GSONConfigList(GSONConfigBase owner, JsonArray json, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.json = json;
|
||||
this.exists = this.initialized = exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection appendSection() {
|
||||
JsonObject object = new JsonObject();
|
||||
json.add(object);
|
||||
owner.modified = true;
|
||||
initialized = true;
|
||||
return new GSONConfigSection(owner, object, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList appendList() {
|
||||
JsonArray array = new JsonArray();
|
||||
json.add(array);
|
||||
owner.modified = true;
|
||||
initialized = true;
|
||||
return new GSONConfigList(owner, array, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendInteger(int value) {
|
||||
json.add(value);
|
||||
owner.modified = true;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendString(String string) {
|
||||
json.add(string);
|
||||
owner.modified = true;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return json.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(int index) {
|
||||
if (index < 0 || index >= json.size())
|
||||
return null;
|
||||
JsonElement el = json.get(index);
|
||||
if (el != null && el.isJsonObject()) {
|
||||
return new GSONConfigSection(owner, el.getAsJsonObject(), true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(int index) {
|
||||
if (index < 0 || index >= json.size())
|
||||
return null;
|
||||
JsonElement el = json.get(index);
|
||||
if (el != null && el.isJsonArray()) {
|
||||
return new GSONConfigList(owner, el.getAsJsonArray(), true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(int index) {
|
||||
if (index < 0 || index >= json.size())
|
||||
return false;
|
||||
JsonElement el = json.get(index);
|
||||
return el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIfInteger(int index, int defaultVal) {
|
||||
if (index < 0 || index >= json.size())
|
||||
return defaultVal;
|
||||
JsonElement el = json.get(index);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isNumber()) {
|
||||
return el.getAsInt();
|
||||
} else {
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(int index) {
|
||||
if (index < 0 || index >= json.size())
|
||||
return false;
|
||||
JsonElement el = json.get(index);
|
||||
return el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(int index, String defaultVal) {
|
||||
if (index < 0 || index >= json.size())
|
||||
return defaultVal;
|
||||
JsonElement el = json.get(index);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
|
||||
return el.getAsString();
|
||||
} else {
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.gson;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
import net.lax1dude.eaglercraft.backend.server.util.GsonLenient;
|
||||
|
||||
public class GSONConfigLoader {
|
||||
|
||||
private static final Gson GSON = GsonLenient.setLenient(new GsonBuilder()).setPrettyPrinting().serializeNulls()
|
||||
.create();
|
||||
|
||||
public static IEaglerConfig getConfigFile(File file) throws IOException {
|
||||
JsonObject obj;
|
||||
try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
|
||||
obj = GSON.fromJson(reader, JsonObject.class);
|
||||
} catch (FileNotFoundException ex) {
|
||||
obj = new JsonObject();
|
||||
} catch (JsonParseException ex) {
|
||||
throw new IOException("JSON config file has a syntax error: " + file.getAbsolutePath(), ex);
|
||||
}
|
||||
return getConfigFile(file, obj);
|
||||
}
|
||||
|
||||
public static IEaglerConfig getConfigFile(File file, JsonObject jsonObject) throws IOException {
|
||||
GSONConfigBase base = new GSONConfigBase(file);
|
||||
base.root = new GSONConfigSection(base, jsonObject, jsonObject.size() > 0);
|
||||
return base;
|
||||
}
|
||||
|
||||
public static void writeConfigFile(JsonObject configIn, File file) throws IOException {
|
||||
File p = file.getAbsoluteFile().getParentFile();
|
||||
if (p != null && !p.isDirectory() && !p.mkdirs()) {
|
||||
throw new IOException("Could not create directory: " + p.getAbsolutePath());
|
||||
}
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
||||
GSON.toJson(configIn, writer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.google.common.collect.ImmutableList
|
||||
* com.google.gson.JsonArray
|
||||
* com.google.gson.JsonElement
|
||||
* com.google.gson.JsonObject
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.gson;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.gson.GSONConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.gson.GSONConfigList;
|
||||
|
||||
public class GSONConfigSection
|
||||
implements IEaglerConfSection {
|
||||
private final GSONConfigBase owner;
|
||||
final JsonObject json;
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
protected GSONConfigSection(GSONConfigBase owner, JsonObject json, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.json = json;
|
||||
this.exists = this.initialized = exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonObject()) {
|
||||
return new GSONConfigSection(this.owner, el.getAsJsonObject(), true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getSection(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonObject()) {
|
||||
return new GSONConfigSection(this.owner, el.getAsJsonObject(), true);
|
||||
}
|
||||
JsonObject obj = new JsonObject();
|
||||
this.json.add(name, (JsonElement)obj);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new GSONConfigSection(this.owner, obj, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonArray()) {
|
||||
return new GSONConfigList(this.owner, el.getAsJsonArray(), true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getList(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonArray()) {
|
||||
return new GSONConfigList(this.owner, el.getAsJsonArray(), true);
|
||||
}
|
||||
JsonArray obj = new JsonArray();
|
||||
this.json.add(name, (JsonElement)obj);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new GSONConfigList(this.owner, obj, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getKeys() {
|
||||
return ImmutableList.copyOf((Collection)this.json.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
return el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
return el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isBoolean() && el.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, boolean defaultValue, String comment) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isBoolean()) {
|
||||
return el.getAsBoolean();
|
||||
}
|
||||
this.json.addProperty(name, Boolean.valueOf(defaultValue));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, Supplier<Boolean> defaultValue, String comment) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isBoolean()) {
|
||||
return el.getAsBoolean();
|
||||
}
|
||||
boolean b = defaultValue.get();
|
||||
this.json.addProperty(name, Boolean.valueOf(b));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
return el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, int defaultValue, String comment) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isNumber()) {
|
||||
return el.getAsJsonPrimitive().getAsInt();
|
||||
}
|
||||
this.json.addProperty(name, (Number)defaultValue);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, Supplier<Integer> defaultValue, String comment) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isNumber()) {
|
||||
return el.getAsJsonPrimitive().getAsInt();
|
||||
}
|
||||
Integer i = defaultValue.get();
|
||||
this.json.addProperty(name, (Number)i);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
return el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(String name) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
|
||||
return el.getAsString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, String defaultValue, String comment) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
|
||||
return el.getAsString();
|
||||
}
|
||||
this.json.addProperty(name, defaultValue);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, Supplier<String> defaultValue, String comment) {
|
||||
JsonElement el = this.json.get(name);
|
||||
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
|
||||
return el.getAsString();
|
||||
}
|
||||
String d = defaultValue.get();
|
||||
this.json.addProperty(name, d);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.nightconfig;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.EnumConfigFormat;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
|
||||
public class NightConfigBase implements IEaglerConfig {
|
||||
|
||||
NightConfigSection root;
|
||||
boolean modified;
|
||||
|
||||
@Override
|
||||
public EnumConfigFormat getFormat() {
|
||||
return EnumConfigFormat.TOML;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveIfModified() throws IOException {
|
||||
if (modified) {
|
||||
NightConfigLoader.writeConfigFile((CommentedFileConfig) root.config);
|
||||
modified = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.electronwill.nightconfig.core.CommentedConfig
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.nightconfig;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigLoader;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigSection;
|
||||
|
||||
public class NightConfigList
|
||||
implements IEaglerConfList {
|
||||
private final NightConfigBase owner;
|
||||
private final List<Object> data;
|
||||
private final IContext commentSetter;
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
public NightConfigList(NightConfigBase owner, List<Object> list, IContext commentSetter, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.data = list;
|
||||
this.commentSetter = commentSetter;
|
||||
this.exists = this.initialized = exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
this.commentSetter.setComment(NightConfigLoader.createComment(comment));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection appendSection() {
|
||||
CommentedConfig conf = this.commentSetter.genSection();
|
||||
this.data.add(conf);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new NightConfigSection(this.owner, conf, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList appendList() {
|
||||
ArrayList<Object> list = new ArrayList<Object>();
|
||||
this.data.add(list);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new NightConfigList(this.owner, list, new IContext(){
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentedConfig genSection() {
|
||||
return NightConfigList.this.commentSetter.genSection();
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendInteger(int value) {
|
||||
this.data.add(value);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendString(String string) {
|
||||
this.data.add(string);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return this.data.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(int index) {
|
||||
if (index < 0 || index >= this.data.size()) {
|
||||
return null;
|
||||
}
|
||||
Object val = this.data.get(index);
|
||||
return val instanceof CommentedConfig ? new NightConfigSection(this.owner, (CommentedConfig)val, null, true) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(int index) {
|
||||
if (index < 0 || index >= this.data.size()) {
|
||||
return null;
|
||||
}
|
||||
Object val = this.data.get(index);
|
||||
return val instanceof List ? new NightConfigList(this.owner, (List)val, new IContext(){
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentedConfig genSection() {
|
||||
return NightConfigList.this.commentSetter.genSection();
|
||||
}
|
||||
}, true) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(int index) {
|
||||
if (index < 0 || index >= this.data.size()) {
|
||||
return false;
|
||||
}
|
||||
return this.data.get(index) instanceof Number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIfInteger(int index, int defaultVal) {
|
||||
if (index < 0 || index >= this.data.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Object val = this.data.get(index);
|
||||
return val instanceof Number ? ((Number)val).intValue() : defaultVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(int index) {
|
||||
if (index < 0 || index >= this.data.size()) {
|
||||
return false;
|
||||
}
|
||||
return this.data.get(index) instanceof String;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(int index, String defaultVal) {
|
||||
if (index < 0 || index >= this.data.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Object val = this.data.get(index);
|
||||
return val instanceof String ? (String)val : defaultVal;
|
||||
}
|
||||
|
||||
public static interface IContext {
|
||||
public void setComment(String var1);
|
||||
|
||||
public CommentedConfig genSection();
|
||||
}
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.nightconfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.WrapUtil;
|
||||
|
||||
public class NightConfigLoader {
|
||||
|
||||
public static final int TOML_COMMENT_WRAP = 80;
|
||||
|
||||
public static IEaglerConfig getConfigFile(File file) throws IOException {
|
||||
CommentedFileConfig config = null;
|
||||
try {
|
||||
config = CommentedFileConfig.builder(file).sync().preserveInsertionOrder()
|
||||
.onFileNotFound(FileNotFoundAction.READ_NOTHING).build();
|
||||
config.load();
|
||||
} catch (Exception ex) {
|
||||
try {
|
||||
if (config != null) {
|
||||
config.close();
|
||||
}
|
||||
} catch (Exception exx) {
|
||||
}
|
||||
throw new IOException("Failed to load config file: " + file.getAbsolutePath(), ex);
|
||||
}
|
||||
return getConfigFile(config);
|
||||
}
|
||||
|
||||
public static IEaglerConfig getConfigFile(CommentedConfig config) {
|
||||
NightConfigBase ret = new NightConfigBase();
|
||||
ret.root = new NightConfigSection(ret, config, null, config.size() > 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void writeConfigFile(CommentedFileConfig configIn) throws IOException {
|
||||
File p = configIn.getFile().getAbsoluteFile().getParentFile();
|
||||
if (p != null && !p.isDirectory() && !p.mkdirs()) {
|
||||
throw new IOException("Could not create directory: " + p.getAbsolutePath());
|
||||
}
|
||||
try {
|
||||
try {
|
||||
configIn.save();
|
||||
} finally {
|
||||
configIn.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new IOException("Failed to save config file: " + configIn.getFile().getAbsolutePath(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String createComment(String stringIn) {
|
||||
if (stringIn != null) {
|
||||
return " " + WrapUtil.wrap(stringIn, TOML_COMMENT_WRAP, System.lineSeparator() + " ", false, " ");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.electronwill.nightconfig.core.CommentedConfig
|
||||
* com.google.common.collect.ImmutableList
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.nightconfig;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.nightconfig.NightConfigLoader;
|
||||
|
||||
public class NightConfigSection
|
||||
implements IEaglerConfSection {
|
||||
private final NightConfigBase owner;
|
||||
final CommentedConfig config;
|
||||
private final Consumer<String> commentSetter;
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
public NightConfigSection(NightConfigBase owner, CommentedConfig config, Consumer<String> commentSetter, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.config = config;
|
||||
this.commentSetter = commentSetter;
|
||||
this.exists = this.initialized = exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
if (this.commentSetter != null) {
|
||||
this.commentSetter.accept(NightConfigLoader.createComment(comment));
|
||||
this.owner.modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof CommentedConfig ? new NightConfigSection(this.owner, (CommentedConfig)o, str -> this.config.setComment(k, str), true) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getSection(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof CommentedConfig) {
|
||||
CommentedConfig o2 = (CommentedConfig)o;
|
||||
return new NightConfigSection(this.owner, o2, str -> this.config.setComment(k, str), true);
|
||||
}
|
||||
CommentedConfig sub = this.config.createSubConfig();
|
||||
this.config.set(k, (Object)sub);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new NightConfigSection(this.owner, sub, str -> this.config.setComment(k, str), false);
|
||||
}
|
||||
|
||||
private NightConfigList.IContext bindListContext(final List<String> key) {
|
||||
return new NightConfigList.IContext(){
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
NightConfigSection.this.config.setComment(key, comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentedConfig genSection() {
|
||||
return NightConfigSection.this.config.createSubConfig();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof List ? new NightConfigList(this.owner, (List)o, this.bindListContext(k), true) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getList(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof List) {
|
||||
return new NightConfigList(this.owner, (List)o, this.bindListContext(k), true);
|
||||
}
|
||||
ArrayList<Object> sub = new ArrayList<Object>();
|
||||
this.config.set(k, sub);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new NightConfigList(this.owner, sub, this.bindListContext(k), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getKeys() {
|
||||
return ImmutableList.copyOf(this.config.valueMap().keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof Boolean && (Boolean)o != false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, boolean defaultValue, String comment) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof Boolean) {
|
||||
Boolean o2 = (Boolean)o;
|
||||
return o2;
|
||||
}
|
||||
this.config.set(k, (Object)defaultValue);
|
||||
if (comment != null) {
|
||||
this.config.setComment(k, NightConfigLoader.createComment(comment));
|
||||
}
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, Supplier<Boolean> defaultValue, String comment) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof Boolean) {
|
||||
Boolean o2 = (Boolean)o;
|
||||
return o2;
|
||||
}
|
||||
Boolean d = defaultValue.get();
|
||||
this.config.set(k, (Object)d);
|
||||
if (comment != null) {
|
||||
this.config.setComment(k, NightConfigLoader.createComment(comment));
|
||||
}
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof Number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, int defaultValue, String comment) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof Number) {
|
||||
Number o2 = (Number)o;
|
||||
return o2.intValue();
|
||||
}
|
||||
this.config.set(k, (Object)defaultValue);
|
||||
if (comment != null) {
|
||||
this.config.setComment(k, NightConfigLoader.createComment(comment));
|
||||
}
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, Supplier<Integer> defaultValue, String comment) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof Number) {
|
||||
Number o2 = (Number)o;
|
||||
return o2.intValue();
|
||||
}
|
||||
Integer d = defaultValue.get();
|
||||
this.config.set(k, (Object)d);
|
||||
if (comment != null) {
|
||||
this.config.setComment(k, NightConfigLoader.createComment(comment));
|
||||
}
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof String;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(String name) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
return o instanceof String ? (String)o : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, String defaultValue, String comment) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof String) {
|
||||
String str = (String)o;
|
||||
return str;
|
||||
}
|
||||
this.config.set(k, (Object)defaultValue);
|
||||
if (comment != null) {
|
||||
this.config.setComment(k, NightConfigLoader.createComment(comment));
|
||||
}
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, Supplier<String> defaultValue, String comment) {
|
||||
List<String> k = Collections.singletonList(name);
|
||||
Object o = this.config.get(k);
|
||||
if (o instanceof String) {
|
||||
String str = (String)o;
|
||||
return str;
|
||||
}
|
||||
String d = defaultValue.get();
|
||||
this.config.set(k, (Object)d);
|
||||
if (comment != null) {
|
||||
this.config.setComment(k, NightConfigLoader.createComment(comment));
|
||||
}
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
|
||||
public class YAMLConfigLoader {
|
||||
|
||||
private static final boolean MODERN;
|
||||
|
||||
static {
|
||||
boolean b = false;
|
||||
try {
|
||||
Class.forName("org.yaml.snakeyaml.LoaderOptions").getMethod("setProcessComments", boolean.class);
|
||||
b = true;
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
}
|
||||
MODERN = b;
|
||||
}
|
||||
|
||||
public static IEaglerConfig getConfigFile(File file) throws IOException {
|
||||
if (MODERN) {
|
||||
return net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigLoader.getConfigFile(file);
|
||||
} else {
|
||||
return net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigLoader.getConfigFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.yaml.snakeyaml.error.Mark
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.NodeTuple
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.SequenceNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.ReflectUtil;
|
||||
import org.yaml.snakeyaml.error.Mark;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.SequenceNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
class LegacyHelper {
|
||||
private static final boolean HAS_FLOWSTYLE;
|
||||
private static final boolean HAS_SCALARSTYLE;
|
||||
private static final Constructor<MappingNode> ctor_MappingNode;
|
||||
private static final Constructor<SequenceNode> ctor_SequenceNode;
|
||||
private static final Object flowStyle;
|
||||
private static final Constructor<ScalarNode> ctor_ScalarNode;
|
||||
private static final Method meth_createStyle;
|
||||
|
||||
LegacyHelper() {
|
||||
}
|
||||
|
||||
public static MappingNode mappingNode(Tag tag, List<NodeTuple> lst) {
|
||||
try {
|
||||
if (HAS_FLOWSTYLE) {
|
||||
return ctor_MappingNode.newInstance(tag, lst, flowStyle);
|
||||
}
|
||||
return ctor_MappingNode.newInstance(tag, lst, Boolean.FALSE);
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
throw ReflectUtil.propagateReflectThrowable(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static SequenceNode sequenceNode(Tag tag, List<Node> lst) {
|
||||
try {
|
||||
if (HAS_FLOWSTYLE) {
|
||||
return ctor_SequenceNode.newInstance(tag, lst, flowStyle);
|
||||
}
|
||||
return ctor_SequenceNode.newInstance(tag, lst, Boolean.FALSE);
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
throw ReflectUtil.propagateReflectThrowable(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static ScalarNode scalarNode(Tag tag, String value, Character style) {
|
||||
try {
|
||||
if (HAS_SCALARSTYLE) {
|
||||
return ctor_ScalarNode.newInstance(tag, value, null, null, meth_createStyle.invoke(null, style));
|
||||
}
|
||||
return ctor_ScalarNode.newInstance(tag, value, null, null, style);
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
throw ReflectUtil.propagateReflectThrowable(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixScalars(Node data, Field scalarStyle) {
|
||||
block6: {
|
||||
block7: {
|
||||
block5: {
|
||||
if (!(data instanceof ScalarNode)) break block5;
|
||||
ScalarNode s = (ScalarNode)data;
|
||||
try {
|
||||
Character c = (Character)scalarStyle.get(s);
|
||||
if (c != null && c.charValue() == '\u0000') {
|
||||
scalarStyle.set(s, null);
|
||||
}
|
||||
}
|
||||
catch (ReflectiveOperationException reflectiveOperationException) {}
|
||||
break block6;
|
||||
}
|
||||
if (!(data instanceof SequenceNode)) break block7;
|
||||
SequenceNode s = (SequenceNode)data;
|
||||
for (Node n : s.getValue()) {
|
||||
LegacyHelper.fixScalars(n, scalarStyle);
|
||||
}
|
||||
break block6;
|
||||
}
|
||||
if (!(data instanceof MappingNode)) break block6;
|
||||
MappingNode s = (MappingNode)data;
|
||||
for (NodeTuple n : s.getValue()) {
|
||||
LegacyHelper.fixScalars(n.getKeyNode(), scalarStyle);
|
||||
LegacyHelper.fixScalars(n.getValueNode(), scalarStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Class<?> flowStyleClz = null;
|
||||
Class<?> scalarStyleClz = null;
|
||||
try {
|
||||
flowStyleClz = Class.forName("org.yaml.snakeyaml.DumperOptions$FlowStyle");
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
// empty catch block
|
||||
}
|
||||
try {
|
||||
scalarStyleClz = Class.forName("org.yaml.snakeyaml.DumperOptions$ScalarStyle");
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
// empty catch block
|
||||
}
|
||||
try {
|
||||
Constructor _ctor_MappingNode = null;
|
||||
Constructor _ctor_SequenceNode = null;
|
||||
Object _flowStyle = null;
|
||||
if (flowStyleClz != null) {
|
||||
try {
|
||||
_ctor_MappingNode = MappingNode.class.getConstructor(Tag.class, List.class, flowStyleClz);
|
||||
_ctor_SequenceNode = SequenceNode.class.getConstructor(Tag.class, List.class, flowStyleClz);
|
||||
_flowStyle = Enum.valueOf((Class)flowStyleClz, "BLOCK");
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
flowStyleClz = null;
|
||||
}
|
||||
}
|
||||
if (flowStyleClz == null) {
|
||||
_ctor_MappingNode = MappingNode.class.getConstructor(Tag.class, List.class, Boolean.class);
|
||||
_ctor_SequenceNode = SequenceNode.class.getConstructor(Tag.class, List.class, Boolean.class);
|
||||
_flowStyle = null;
|
||||
}
|
||||
Constructor _ctor_ScalarNode = null;
|
||||
Method _meth_createStyle = null;
|
||||
if (scalarStyleClz != null) {
|
||||
try {
|
||||
_ctor_ScalarNode = ScalarNode.class.getConstructor(Tag.class, String.class, Mark.class, Mark.class, scalarStyleClz);
|
||||
_meth_createStyle = scalarStyleClz.getMethod("createStyle", Character.class);
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
scalarStyleClz = null;
|
||||
}
|
||||
}
|
||||
if (scalarStyleClz == null) {
|
||||
_ctor_ScalarNode = ScalarNode.class.getConstructor(Tag.class, String.class, Mark.class, Mark.class, Character.class);
|
||||
_meth_createStyle = null;
|
||||
}
|
||||
ctor_MappingNode = _ctor_MappingNode;
|
||||
ctor_SequenceNode = _ctor_SequenceNode;
|
||||
flowStyle = _flowStyle;
|
||||
ctor_ScalarNode = _ctor_ScalarNode;
|
||||
meth_createStyle = _meth_createStyle;
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
HAS_FLOWSTYLE = flowStyleClz != null;
|
||||
HAS_SCALARSTYLE = scalarStyleClz != null;
|
||||
}
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.EnumConfigFormat;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
|
||||
public class YAMLConfigBase implements IEaglerConfig {
|
||||
|
||||
final File file;
|
||||
YAMLConfigSection root;
|
||||
boolean modified;
|
||||
|
||||
YAMLConfigBase(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumConfigFormat getFormat() {
|
||||
return EnumConfigFormat.YAML;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveIfModified() throws IOException {
|
||||
if (modified) {
|
||||
YAMLConfigLoader.writeConfigFile(root.yaml, file);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.NodeTuple
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.SequenceNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.LegacyHelper;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigSection;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.SequenceNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
public class YAMLConfigList
|
||||
implements IEaglerConfList {
|
||||
private final YAMLConfigBase owner;
|
||||
final SequenceNode yaml;
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
public YAMLConfigList(YAMLConfigBase owner, SequenceNode yaml, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.yaml = yaml;
|
||||
this.exists = this.initialized = exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection appendSection() {
|
||||
MappingNode obj = LegacyHelper.mappingNode(Tag.MAP, new ArrayList<NodeTuple>());
|
||||
this.yaml.getValue().add(obj);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigSection(this.owner, obj, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList appendList() {
|
||||
SequenceNode obj = LegacyHelper.sequenceNode(Tag.SEQ, new ArrayList<Node>());
|
||||
this.yaml.getValue().add(obj);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigList(this.owner, obj, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendInteger(int value) {
|
||||
this.yaml.getValue().add(LegacyHelper.scalarNode(Tag.INT, Integer.toString(value), null));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendString(String string) {
|
||||
this.yaml.getValue().add(LegacyHelper.scalarNode(Tag.STR, string, Character.valueOf('\'')));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return this.yaml.getValue().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return null;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t instanceof MappingNode) {
|
||||
MappingNode tt = (MappingNode)t;
|
||||
return new YAMLConfigSection(this.owner, tt, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return null;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t instanceof SequenceNode) {
|
||||
SequenceNode tt = (SequenceNode)t;
|
||||
return new YAMLConfigList(this.owner, tt, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return false;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t != null && t instanceof ScalarNode) {
|
||||
ScalarNode tt = (ScalarNode)t;
|
||||
try {
|
||||
Double.parseDouble(tt.getValue());
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIfInteger(int index, int defaultVal) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t != null && t instanceof ScalarNode) {
|
||||
ScalarNode tt = (ScalarNode)t;
|
||||
try {
|
||||
return (int)Double.parseDouble(tt.getValue());
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return false;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
return t != null && t instanceof ScalarNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(int index, String defaultVal) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t != null && t instanceof ScalarNode) {
|
||||
ScalarNode tt = (ScalarNode)t;
|
||||
return tt.getValue();
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.yaml.snakeyaml.DumperOptions
|
||||
* org.yaml.snakeyaml.DumperOptions$FlowStyle
|
||||
* org.yaml.snakeyaml.Yaml
|
||||
* org.yaml.snakeyaml.error.YAMLException
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.NodeTuple
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
* org.yaml.snakeyaml.representer.BaseRepresenter
|
||||
* org.yaml.snakeyaml.representer.Represent
|
||||
* org.yaml.snakeyaml.representer.Representer
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.LegacyHelper;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigSection;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
import org.yaml.snakeyaml.representer.BaseRepresenter;
|
||||
import org.yaml.snakeyaml.representer.Represent;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
public class YAMLConfigLoader {
|
||||
private static final Yaml YAML;
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static IEaglerConfig getConfigFile(File file) throws IOException {
|
||||
MappingNode obj;
|
||||
try (InputStreamReader reader = new InputStreamReader((InputStream)new FileInputStream(file), StandardCharsets.UTF_8);){
|
||||
Yaml yaml = YAML;
|
||||
synchronized (yaml) {
|
||||
obj = (MappingNode)YAML.compose((Reader)reader);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
obj = null;
|
||||
}
|
||||
catch (YAMLException ex) {
|
||||
throw new IOException("YAML config file has a syntax error: " + file.getAbsolutePath(), ex);
|
||||
}
|
||||
if (obj == null) {
|
||||
obj = LegacyHelper.mappingNode(Tag.MAP, new ArrayList<NodeTuple>());
|
||||
}
|
||||
if (!(obj instanceof MappingNode)) {
|
||||
throw new IOException("Root node " + obj.getClass().getSimpleName() + " is not a map!");
|
||||
}
|
||||
return YAMLConfigLoader.getConfigFile(file, obj);
|
||||
}
|
||||
|
||||
public static IEaglerConfig getConfigFile(File file, MappingNode node) throws IOException {
|
||||
YAMLConfigBase base = new YAMLConfigBase(file);
|
||||
base.root = new YAMLConfigSection(base, node, node.getValue().size() > 0);
|
||||
return base;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static void writeConfigFile(Node configIn, File file) throws IOException {
|
||||
File p = file.getAbsoluteFile().getParentFile();
|
||||
if (p != null && !p.isDirectory() && !p.mkdirs()) {
|
||||
throw new IOException("Could not create directory: " + p.getAbsolutePath());
|
||||
}
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter((OutputStream)new FileOutputStream(file), StandardCharsets.UTF_8);){
|
||||
Yaml yaml = YAML;
|
||||
synchronized (yaml) {
|
||||
YAML.dump((Object)configIn, (Writer)writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Representer representer;
|
||||
DumperOptions dumpOpts = new DumperOptions();
|
||||
dumpOpts.setPrettyFlow(true);
|
||||
dumpOpts.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
|
||||
try {
|
||||
representer = (Representer)Representer.class.getConstructor(DumperOptions.class).newInstance(dumpOpts);
|
||||
}
|
||||
catch (ReflectiveOperationException ex) {
|
||||
try {
|
||||
representer = (Representer)Representer.class.getConstructor(new Class[0]).newInstance(new Object[0]);
|
||||
}
|
||||
catch (ReflectiveOperationException exx) {
|
||||
throw new ExceptionInInitializerError(exx);
|
||||
}
|
||||
}
|
||||
Field scalarStyleField = null;
|
||||
try {
|
||||
scalarStyleField = ScalarNode.class.getDeclaredField("style");
|
||||
if (scalarStyleField.getType() == Character.class) {
|
||||
scalarStyleField.setAccessible(true);
|
||||
} else {
|
||||
scalarStyleField = null;
|
||||
}
|
||||
}
|
||||
catch (ReflectiveOperationException exx) {
|
||||
// empty catch block
|
||||
}
|
||||
final Field scalarStyleFieldF = scalarStyleField;
|
||||
try {
|
||||
Field f = BaseRepresenter.class.getDeclaredField("multiRepresenters");
|
||||
f.setAccessible(true);
|
||||
((Map)f.get(representer)).put(Node.class, new Represent(){
|
||||
|
||||
public Node representData(Object data) {
|
||||
if (scalarStyleFieldF != null) {
|
||||
LegacyHelper.fixScalars((Node)data, scalarStyleFieldF);
|
||||
}
|
||||
return (Node)data;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (ReflectiveOperationException exx) {
|
||||
throw new ExceptionInInitializerError(exx);
|
||||
}
|
||||
YAML = new Yaml(representer, dumpOpts);
|
||||
}
|
||||
}
|
||||
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.google.common.collect.ImmutableList
|
||||
* com.google.common.collect.ImmutableList$Builder
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.NodeTuple
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.SequenceNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.LegacyHelper;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.legacy.YAMLConfigList;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.SequenceNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
public class YAMLConfigSection
|
||||
implements IEaglerConfSection {
|
||||
private final YAMLConfigBase owner;
|
||||
final MappingNode yaml;
|
||||
final Map<String, NodeTuple> accelerator = new HashMap<String, NodeTuple>();
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
protected YAMLConfigSection(YAMLConfigBase owner, MappingNode yaml, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.yaml = yaml;
|
||||
this.exists = this.initialized = exists;
|
||||
this.rehash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
public void rehash() {
|
||||
this.accelerator.clear();
|
||||
for (NodeTuple t : this.yaml.getValue()) {
|
||||
Node key = t.getKeyNode();
|
||||
if (!(key instanceof ScalarNode)) continue;
|
||||
ScalarNode key2 = (ScalarNode)key;
|
||||
this.accelerator.put(key2.getValue(), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof MappingNode) {
|
||||
MappingNode value2 = (MappingNode)t.getValueNode();
|
||||
return new YAMLConfigSection(this.owner, value2, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getSection(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof MappingNode) {
|
||||
MappingNode value2 = (MappingNode)t.getValueNode();
|
||||
return new YAMLConfigSection(this.owner, value2, true);
|
||||
}
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
MappingNode obj = LegacyHelper.mappingNode(Tag.MAP, new ArrayList<NodeTuple>());
|
||||
NodeTuple tt = new NodeTuple((Node)key, (Node)obj);
|
||||
this.accelerator.put(name, tt);
|
||||
this.yaml.getValue().add(tt);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigSection(this.owner, obj, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof SequenceNode) {
|
||||
SequenceNode value2 = (SequenceNode)t.getValueNode();
|
||||
return new YAMLConfigList(this.owner, value2, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getList(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof SequenceNode) {
|
||||
SequenceNode value2 = (SequenceNode)t.getValueNode();
|
||||
return new YAMLConfigList(this.owner, value2, true);
|
||||
}
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
SequenceNode obj = LegacyHelper.sequenceNode(Tag.SEQ, new ArrayList<Node>());
|
||||
NodeTuple tt = new NodeTuple((Node)key, (Node)obj);
|
||||
this.accelerator.put(name, tt);
|
||||
this.yaml.getValue().add(tt);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigList(this.owner, obj, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getKeys() {
|
||||
ImmutableList.Builder builder = ImmutableList.builder();
|
||||
for (NodeTuple t : this.yaml.getValue()) {
|
||||
Node key = t.getKeyNode();
|
||||
if (!(key instanceof ScalarNode)) continue;
|
||||
ScalarNode key2 = (ScalarNode)key;
|
||||
builder.add((Object)key2.getValue());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
String str = value2.getValue().toLowerCase();
|
||||
return "false".equals(str) || "true".equals(str);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
return t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode && Boolean.valueOf(((ScalarNode)t.getValueNode()).getValue()) != false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, boolean defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
String str = value2.getValue().toLowerCase();
|
||||
boolean b = false;
|
||||
if ("false".equals(str) || (b = "true".equals(str))) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
ScalarNode node = LegacyHelper.scalarNode(Tag.BOOL, Boolean.toString(defaultValue), null);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, Supplier<Boolean> defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
String str = value2.getValue().toLowerCase();
|
||||
boolean b = false;
|
||||
if ("false".equals(str) || (b = "true".equals(str))) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
boolean b = defaultValue.get();
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
ScalarNode node = LegacyHelper.scalarNode(Tag.BOOL, Boolean.toString(b), null);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
try {
|
||||
Double.parseDouble(value2.getValue());
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, int defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
try {
|
||||
return (int)Double.parseDouble(value2.getValue());
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
ScalarNode node = LegacyHelper.scalarNode(Tag.INT, Integer.toString(defaultValue), null);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, Supplier<Integer> defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
try {
|
||||
return (int)Double.parseDouble(value2.getValue());
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
int i = defaultValue.get();
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
ScalarNode node = LegacyHelper.scalarNode(Tag.INT, Integer.toString(i), null);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
return t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
return value2.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, String defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
return value2.getValue();
|
||||
}
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
ScalarNode node = LegacyHelper.scalarNode(Tag.STR, defaultValue, Character.valueOf('\''));
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, Supplier<String> defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
return value2.getValue();
|
||||
}
|
||||
String str = defaultValue.get();
|
||||
ScalarNode key = LegacyHelper.scalarNode(Tag.STR, name, null);
|
||||
ScalarNode node = LegacyHelper.scalarNode(Tag.STR, str, Character.valueOf('\''));
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.EnumConfigFormat;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
|
||||
public class YAMLConfigBase implements IEaglerConfig {
|
||||
|
||||
final File file;
|
||||
YAMLConfigSection root;
|
||||
boolean modified;
|
||||
|
||||
YAMLConfigBase(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumConfigFormat getFormat() {
|
||||
return EnumConfigFormat.YAML;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveIfModified() throws IOException {
|
||||
if (modified) {
|
||||
YAMLConfigLoader.writeConfigFile(root.yaml, file);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.yaml.snakeyaml.DumperOptions$FlowStyle
|
||||
* org.yaml.snakeyaml.DumperOptions$ScalarStyle
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.SequenceNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigSection;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.SequenceNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
public class YAMLConfigList
|
||||
implements IEaglerConfList {
|
||||
private final YAMLConfigBase owner;
|
||||
final SequenceNode yaml;
|
||||
private final Consumer<String> commentSetter;
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
public YAMLConfigList(YAMLConfigBase owner, SequenceNode yaml, Consumer<String> commentSetter, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.yaml = yaml;
|
||||
this.commentSetter = commentSetter;
|
||||
this.exists = this.initialized = exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
if (this.commentSetter != null) {
|
||||
this.commentSetter.accept(comment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection appendSection() {
|
||||
MappingNode obj = new MappingNode(Tag.MAP, new ArrayList(), DumperOptions.FlowStyle.BLOCK);
|
||||
this.yaml.getValue().add(obj);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigSection(this.owner, obj, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList appendList() {
|
||||
SequenceNode obj = new SequenceNode(Tag.SEQ, new ArrayList(), DumperOptions.FlowStyle.BLOCK);
|
||||
this.yaml.getValue().add(obj);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigList(this.owner, obj, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendInteger(int value) {
|
||||
this.yaml.getValue().add(new ScalarNode(Tag.INT, Integer.toString(value), null, null, DumperOptions.ScalarStyle.PLAIN));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendString(String string) {
|
||||
this.yaml.getValue().add(new ScalarNode(Tag.STR, string, null, null, DumperOptions.ScalarStyle.SINGLE_QUOTED));
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return this.yaml.getValue().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return null;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t instanceof MappingNode) {
|
||||
MappingNode tt = (MappingNode)t;
|
||||
return new YAMLConfigSection(this.owner, tt, null, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return null;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t instanceof SequenceNode) {
|
||||
SequenceNode tt = (SequenceNode)t;
|
||||
return new YAMLConfigList(this.owner, tt, null, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return false;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t != null && t instanceof ScalarNode) {
|
||||
ScalarNode tt = (ScalarNode)t;
|
||||
try {
|
||||
Double.parseDouble(tt.getValue());
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIfInteger(int index, int defaultVal) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t != null && t instanceof ScalarNode) {
|
||||
ScalarNode tt = (ScalarNode)t;
|
||||
try {
|
||||
return (int)Double.parseDouble(tt.getValue());
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(int index) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return false;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
return t != null && t instanceof ScalarNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(int index, String defaultVal) {
|
||||
List lst = this.yaml.getValue();
|
||||
if (index < 0 || index >= lst.size()) {
|
||||
return defaultVal;
|
||||
}
|
||||
Node t = (Node)lst.get(index);
|
||||
if (t != null && t instanceof ScalarNode) {
|
||||
ScalarNode tt = (ScalarNode)t;
|
||||
return tt.getValue();
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.yaml.snakeyaml.DumperOptions
|
||||
* org.yaml.snakeyaml.DumperOptions$FlowStyle
|
||||
* org.yaml.snakeyaml.LoaderOptions
|
||||
* org.yaml.snakeyaml.Yaml
|
||||
* org.yaml.snakeyaml.comments.CommentLine
|
||||
* org.yaml.snakeyaml.comments.CommentType
|
||||
* org.yaml.snakeyaml.constructor.BaseConstructor
|
||||
* org.yaml.snakeyaml.constructor.Constructor
|
||||
* org.yaml.snakeyaml.error.YAMLException
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
* org.yaml.snakeyaml.representer.Representer
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfig;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.WrapUtil;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigSection;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.comments.CommentLine;
|
||||
import org.yaml.snakeyaml.comments.CommentType;
|
||||
import org.yaml.snakeyaml.constructor.BaseConstructor;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
public class YAMLConfigLoader {
|
||||
private static final Yaml YAML;
|
||||
public static final int YAML_COMMENT_WRAP = 80;
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static IEaglerConfig getConfigFile(File file) throws IOException {
|
||||
MappingNode obj;
|
||||
try (InputStreamReader reader = new InputStreamReader((InputStream)new FileInputStream(file), StandardCharsets.UTF_8);){
|
||||
Yaml yaml = YAML;
|
||||
synchronized (yaml) {
|
||||
obj = (MappingNode)YAML.compose((Reader)reader);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
obj = null;
|
||||
}
|
||||
catch (YAMLException ex) {
|
||||
throw new IOException("YAML config file has a syntax error: " + file.getAbsolutePath(), ex);
|
||||
}
|
||||
if (obj == null) {
|
||||
obj = new MappingNode(Tag.MAP, new ArrayList(), DumperOptions.FlowStyle.BLOCK);
|
||||
}
|
||||
if (!(obj instanceof MappingNode)) {
|
||||
throw new IOException("Root node " + obj.getClass().getSimpleName() + " is not a map!");
|
||||
}
|
||||
return YAMLConfigLoader.getConfigFile(file, obj);
|
||||
}
|
||||
|
||||
public static IEaglerConfig getConfigFile(File file, MappingNode node) throws IOException {
|
||||
YAMLConfigBase base = new YAMLConfigBase(file);
|
||||
base.root = new YAMLConfigSection(base, node, null, node.getValue().size() > 0);
|
||||
return base;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public static void writeConfigFile(Node configIn, File file) throws IOException {
|
||||
File p = file.getAbsoluteFile().getParentFile();
|
||||
if (p != null && !p.isDirectory() && !p.mkdirs()) {
|
||||
throw new IOException("Could not create directory: " + p.getAbsolutePath());
|
||||
}
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter((OutputStream)new FileOutputStream(file), StandardCharsets.UTF_8);){
|
||||
Yaml yaml = YAML;
|
||||
synchronized (yaml) {
|
||||
YAML.serialize(configIn, (Writer)writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void createComment(String text, List<CommentLine> ret) {
|
||||
if (text != null) {
|
||||
String[] lines = WrapUtil.wrap(text, 80, "\n", false, " ").split("\n");
|
||||
for (int i = 0; i < lines.length; ++i) {
|
||||
ret.add(new CommentLine(null, null, " " + lines[i], CommentType.BLOCK));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void createCommentHelper(String text, ScalarNode ret) {
|
||||
List<CommentLine> lst = ret.getBlockComments();
|
||||
if (lst == null) {
|
||||
lst = new ArrayList<CommentLine>();
|
||||
ret.setBlockComments(lst);
|
||||
} else {
|
||||
lst.clear();
|
||||
}
|
||||
YAMLConfigLoader.createComment(text, lst);
|
||||
}
|
||||
|
||||
static {
|
||||
LoaderOptions loadOpts = new LoaderOptions();
|
||||
try {
|
||||
LoaderOptions.class.getMethod("setProcessComments", Boolean.TYPE).invoke((Object)loadOpts, true);
|
||||
}
|
||||
catch (ReflectiveOperationException reflectiveOperationException) {
|
||||
// empty catch block
|
||||
}
|
||||
DumperOptions dumpOpts = new DumperOptions();
|
||||
dumpOpts.setPrettyFlow(true);
|
||||
dumpOpts.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
|
||||
try {
|
||||
DumperOptions.class.getMethod("setProcessComments", Boolean.TYPE).invoke((Object)dumpOpts, true);
|
||||
}
|
||||
catch (ReflectiveOperationException reflectiveOperationException) {
|
||||
// empty catch block
|
||||
}
|
||||
YAML = new Yaml((BaseConstructor)new Constructor(loadOpts), new Representer(dumpOpts), dumpOpts);
|
||||
}
|
||||
}
|
||||
|
||||
+370
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.google.common.collect.ImmutableList
|
||||
* com.google.common.collect.ImmutableList$Builder
|
||||
* org.yaml.snakeyaml.DumperOptions$FlowStyle
|
||||
* org.yaml.snakeyaml.DumperOptions$ScalarStyle
|
||||
* org.yaml.snakeyaml.comments.CommentLine
|
||||
* org.yaml.snakeyaml.nodes.MappingNode
|
||||
* org.yaml.snakeyaml.nodes.Node
|
||||
* org.yaml.snakeyaml.nodes.NodeTuple
|
||||
* org.yaml.snakeyaml.nodes.ScalarNode
|
||||
* org.yaml.snakeyaml.nodes.SequenceNode
|
||||
* org.yaml.snakeyaml.nodes.Tag
|
||||
*/
|
||||
package net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.IEaglerConfSection;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigBase;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigList;
|
||||
import net.lax1dude.eaglercraft.backend.server.config.snakeyaml.modern.YAMLConfigLoader;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.comments.CommentLine;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
import org.yaml.snakeyaml.nodes.ScalarNode;
|
||||
import org.yaml.snakeyaml.nodes.SequenceNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
public class YAMLConfigSection
|
||||
implements IEaglerConfSection {
|
||||
private final YAMLConfigBase owner;
|
||||
final MappingNode yaml;
|
||||
private final Consumer<String> commentSetter;
|
||||
final Map<String, NodeTuple> accelerator = new HashMap<String, NodeTuple>();
|
||||
private final boolean exists;
|
||||
private boolean initialized;
|
||||
|
||||
protected YAMLConfigSection(YAMLConfigBase owner, MappingNode yaml, Consumer<String> commentSetter, boolean exists) {
|
||||
this.owner = owner;
|
||||
this.yaml = yaml;
|
||||
this.commentSetter = commentSetter;
|
||||
this.exists = this.initialized = exists;
|
||||
this.rehash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return this.exists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialized() {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
public void rehash() {
|
||||
this.accelerator.clear();
|
||||
for (NodeTuple t : this.yaml.getValue()) {
|
||||
Node key = t.getKeyNode();
|
||||
if (!(key instanceof ScalarNode)) continue;
|
||||
ScalarNode key2 = (ScalarNode)key;
|
||||
this.accelerator.put(key2.getValue(), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(String comment) {
|
||||
if (this.commentSetter != null) {
|
||||
this.commentSetter.accept(comment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getIfSection(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof MappingNode) {
|
||||
MappingNode value2 = (MappingNode)t.getValueNode();
|
||||
return new YAMLConfigSection(this.owner, value2, comment -> {
|
||||
YAMLConfigLoader.createCommentHelper(comment, (ScalarNode)t.getKeyNode());
|
||||
this.owner.modified = true;
|
||||
}, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfSection getSection(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof MappingNode) {
|
||||
MappingNode value2 = (MappingNode)t.getValueNode();
|
||||
return new YAMLConfigSection(this.owner, value2, comment -> {
|
||||
YAMLConfigLoader.createCommentHelper(comment, (ScalarNode)t.getKeyNode());
|
||||
this.owner.modified = true;
|
||||
}, true);
|
||||
}
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
MappingNode obj = new MappingNode(Tag.MAP, new ArrayList(), DumperOptions.FlowStyle.BLOCK);
|
||||
NodeTuple tt = new NodeTuple((Node)key, (Node)obj);
|
||||
this.accelerator.put(name, tt);
|
||||
this.yaml.getValue().add(tt);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigSection(this.owner, obj, comment -> {
|
||||
YAMLConfigLoader.createCommentHelper(comment, key);
|
||||
this.owner.modified = true;
|
||||
}, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getIfList(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof SequenceNode) {
|
||||
SequenceNode value2 = (SequenceNode)t.getValueNode();
|
||||
return new YAMLConfigList(this.owner, value2, comment -> {
|
||||
YAMLConfigLoader.createCommentHelper(comment, (ScalarNode)t.getKeyNode());
|
||||
this.owner.modified = true;
|
||||
}, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEaglerConfList getList(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof SequenceNode) {
|
||||
SequenceNode value2 = (SequenceNode)t.getValueNode();
|
||||
return new YAMLConfigList(this.owner, value2, comment -> {
|
||||
YAMLConfigLoader.createCommentHelper(comment, (ScalarNode)t.getKeyNode());
|
||||
this.owner.modified = true;
|
||||
}, true);
|
||||
}
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
SequenceNode obj = new SequenceNode(Tag.SEQ, new ArrayList(), DumperOptions.FlowStyle.BLOCK);
|
||||
NodeTuple tt = new NodeTuple((Node)key, (Node)obj);
|
||||
this.accelerator.put(name, tt);
|
||||
this.yaml.getValue().add(tt);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return new YAMLConfigList(this.owner, obj, comment -> {
|
||||
YAMLConfigLoader.createCommentHelper(comment, key);
|
||||
this.owner.modified = true;
|
||||
}, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getKeys() {
|
||||
ImmutableList.Builder builder = ImmutableList.builder();
|
||||
for (NodeTuple t : this.yaml.getValue()) {
|
||||
Node key = t.getKeyNode();
|
||||
if (!(key instanceof ScalarNode)) continue;
|
||||
ScalarNode key2 = (ScalarNode)key;
|
||||
builder.add((Object)key2.getValue());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
String str = value2.getValue().toLowerCase();
|
||||
return "false".equals(str) || "true".equals(str);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
return t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode && Boolean.valueOf(((ScalarNode)t.getValueNode()).getValue()) != false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, boolean defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
String str = value2.getValue().toLowerCase();
|
||||
boolean b = false;
|
||||
if ("false".equals(str) || (b = "true".equals(str))) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
if (comment != null) {
|
||||
ArrayList<CommentLine> lst = new ArrayList<CommentLine>();
|
||||
YAMLConfigLoader.createComment(comment, lst);
|
||||
key.setBlockComments(lst);
|
||||
}
|
||||
ScalarNode node = new ScalarNode(Tag.BOOL, Boolean.toString(defaultValue), null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String name, Supplier<Boolean> defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
String str = value2.getValue().toLowerCase();
|
||||
boolean b = false;
|
||||
if ("false".equals(str) || (b = "true".equals(str))) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
boolean b = defaultValue.get();
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
if (comment != null) {
|
||||
ArrayList<CommentLine> lst = new ArrayList<CommentLine>();
|
||||
YAMLConfigLoader.createComment(comment, lst);
|
||||
key.setBlockComments(lst);
|
||||
}
|
||||
ScalarNode node = new ScalarNode(Tag.BOOL, Boolean.toString(b), null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInteger(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
try {
|
||||
Double.parseDouble(value2.getValue());
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, int defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
try {
|
||||
return (int)Double.parseDouble(value2.getValue());
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
if (comment != null) {
|
||||
ArrayList<CommentLine> lst = new ArrayList<CommentLine>();
|
||||
YAMLConfigLoader.createComment(comment, lst);
|
||||
key.setBlockComments(lst);
|
||||
}
|
||||
ScalarNode node = new ScalarNode(Tag.INT, Integer.toString(defaultValue), null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInteger(String name, Supplier<Integer> defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
try {
|
||||
return (int)Double.parseDouble(value2.getValue());
|
||||
}
|
||||
catch (NumberFormatException numberFormatException) {
|
||||
// empty catch block
|
||||
}
|
||||
}
|
||||
int i = defaultValue.get();
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
if (comment != null) {
|
||||
ArrayList<CommentLine> lst = new ArrayList<CommentLine>();
|
||||
YAMLConfigLoader.createComment(comment, lst);
|
||||
key.setBlockComments(lst);
|
||||
}
|
||||
ScalarNode node = new ScalarNode(Tag.INT, Integer.toString(i), null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isString(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
return t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIfString(String name) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
return value2.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, String defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
return value2.getValue();
|
||||
}
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
if (comment != null) {
|
||||
ArrayList<CommentLine> lst = new ArrayList<CommentLine>();
|
||||
YAMLConfigLoader.createComment(comment, lst);
|
||||
key.setBlockComments(lst);
|
||||
}
|
||||
ScalarNode node = new ScalarNode(Tag.STR, defaultValue, null, null, DumperOptions.ScalarStyle.SINGLE_QUOTED);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String name, Supplier<String> defaultValue, String comment) {
|
||||
NodeTuple t = this.accelerator.get(name);
|
||||
if (t != null && t.getValueNode() != null && t.getValueNode() instanceof ScalarNode) {
|
||||
ScalarNode value2 = (ScalarNode)t.getValueNode();
|
||||
return value2.getValue();
|
||||
}
|
||||
String str = defaultValue.get();
|
||||
ScalarNode key = new ScalarNode(Tag.STR, name, null, null, DumperOptions.ScalarStyle.PLAIN);
|
||||
if (comment != null) {
|
||||
ArrayList<CommentLine> lst = new ArrayList<CommentLine>();
|
||||
YAMLConfigLoader.createComment(comment, lst);
|
||||
key.setBlockComments(lst);
|
||||
}
|
||||
ScalarNode node = new ScalarNode(Tag.STR, str, null, null, DumperOptions.ScalarStyle.SINGLE_QUOTED);
|
||||
t = new NodeTuple((Node)key, (Node)node);
|
||||
this.accelerator.put(name, t);
|
||||
this.yaml.getValue().add(t);
|
||||
this.owner.modified = true;
|
||||
this.initialized = true;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.server.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.config.ReflectUtil;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class GsonLenient {
|
||||
|
||||
private static final Method meth_setStrictness;
|
||||
private static final Object enum_LENIENT;
|
||||
private static final Method meth_setLenient;
|
||||
|
||||
static {
|
||||
Method _meth_setStrictness;
|
||||
Object _enum_LENIENT;
|
||||
Method _meth_setLenient;
|
||||
try {
|
||||
Class<?> class_Strictness = Class.forName("com.google.gson.Strictness");
|
||||
_enum_LENIENT = Enum.valueOf((Class) class_Strictness, "LENIENT");
|
||||
_meth_setStrictness = GsonBuilder.class.getMethod("setStrictness", class_Strictness);
|
||||
_meth_setLenient = null;
|
||||
} catch (IllegalArgumentException | ReflectiveOperationException e) {
|
||||
_meth_setStrictness = null;
|
||||
_enum_LENIENT = null;
|
||||
try {
|
||||
_meth_setLenient = GsonBuilder.class.getMethod("setLenient");
|
||||
} catch (ReflectiveOperationException ee) {
|
||||
_meth_setLenient = null;
|
||||
}
|
||||
}
|
||||
meth_setStrictness = _meth_setStrictness;
|
||||
enum_LENIENT = _enum_LENIENT;
|
||||
meth_setLenient = _meth_setLenient;
|
||||
}
|
||||
|
||||
public static GsonBuilder setLenient(GsonBuilder builder) {
|
||||
try {
|
||||
if (meth_setStrictness != null) {
|
||||
meth_setStrictness.invoke(builder, enum_LENIENT);
|
||||
} else if (meth_setLenient != null) {
|
||||
meth_setLenient.invoke(builder);
|
||||
}
|
||||
return builder;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw ReflectUtil.propagateReflectThrowable(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user