mirror of
https://github.com/plexusorg/Plex.git
synced 2025-01-10 17:17:36 +00:00
Format
This commit is contained in:
parent
770fe65f98
commit
bb8c34e0cd
64
.github/workflows/codeql-analysis.yml
vendored
64
.github/workflows/codeql-analysis.yml
vendored
@ -37,41 +37,41 @@ jobs:
|
|||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 17
|
|
||||||
cache: gradle
|
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
- name: Set up JDK 17
|
||||||
- name: Initialize CodeQL
|
uses: actions/setup-java@v2
|
||||||
uses: github/codeql-action/init@v2
|
with:
|
||||||
with:
|
distribution: temurin
|
||||||
languages: ${{ matrix.language }}
|
java-version: 17
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
cache: gradle
|
||||||
# By default, queries listed here will override any specified in a config file.
|
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Initializes the CodeQL tools for scanning.
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
- name: Initialize CodeQL
|
||||||
- name: Autobuild
|
uses: github/codeql-action/init@v2
|
||||||
uses: github/codeql-action/autobuild@v2
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# 📚 https://git.io/JvXDl
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# and modify them (or add more) to build your code if your project
|
# 📚 https://git.io/JvXDl
|
||||||
# uses a compiled language
|
|
||||||
|
|
||||||
- run: |
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
chmod +x gradlew
|
# and modify them (or add more) to build your code if your project
|
||||||
./gradlew build --no-daemon
|
# uses a compiled language
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- run: |
|
||||||
uses: github/codeql-action/analyze@v2
|
chmod +x gradlew
|
||||||
|
./gradlew build --no-daemon
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
|
@ -9,13 +9,12 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import java.util.Arrays;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public abstract class PlexCommand implements SimpleCommand
|
public abstract class PlexCommand implements SimpleCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -81,7 +80,7 @@ public abstract class PlexCommand implements SimpleCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component component = this.execute(invocation.source(), invocation.source() instanceof ConsoleCommandSource ? null : (Player) invocation.source(), invocation.arguments());
|
Component component = this.execute(invocation.source(), invocation.source() instanceof ConsoleCommandSource ? null : (Player)invocation.source(), invocation.arguments());
|
||||||
if (component != null)
|
if (component != null)
|
||||||
{
|
{
|
||||||
send(invocation.source(), component);
|
send(invocation.source(), component);
|
||||||
|
@ -3,13 +3,12 @@ package dev.plex.config;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.toml.Toml;
|
import dev.plex.toml.Toml;
|
||||||
import dev.plex.toml.TomlWriter;
|
import dev.plex.toml.TomlWriter;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class TomlConfig
|
public class TomlConfig
|
||||||
@ -43,7 +42,8 @@ public class TomlConfig
|
|||||||
{
|
{
|
||||||
this.onCreate.accept(this.toml);
|
this.onCreate.accept(this.toml);
|
||||||
}
|
}
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -57,7 +57,8 @@ public class TomlConfig
|
|||||||
{
|
{
|
||||||
this.onCreate.accept(this.toml);
|
this.onCreate.accept(this.toml);
|
||||||
}
|
}
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -89,7 +90,8 @@ public class TomlConfig
|
|||||||
{
|
{
|
||||||
writer.write(object, this.file);
|
writer.write(object, this.file);
|
||||||
this.load();
|
this.load();
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
|
|||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.ReflectionsUtil;
|
import dev.plex.util.ReflectionsUtil;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -5,6 +5,7 @@ import dev.plex.Plex;
|
|||||||
public class PlexListener
|
public class PlexListener
|
||||||
{
|
{
|
||||||
protected final Plex plugin = Plex.get();
|
protected final Plex plugin = Plex.get();
|
||||||
|
|
||||||
public PlexListener()
|
public PlexListener()
|
||||||
{
|
{
|
||||||
Plex.get().getServer().getEventManager().register(Plex.get(), this);
|
Plex.get().getServer().getEventManager().register(Plex.get(), this);
|
||||||
|
@ -2,18 +2,18 @@ package dev.plex.settings;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import java.util.List;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ServerSettings
|
public class ServerSettings
|
||||||
{
|
{
|
||||||
private final Server server = new Server();
|
private final Server server = new Server();
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Server {
|
public static class Server
|
||||||
|
{
|
||||||
private String name = "Server";
|
private String name = "Server";
|
||||||
private List<String> motd = Lists.newArrayList("%randomgradient%%servername% - %mcversion%", "Another motd");
|
private List<String> motd = Lists.newArrayList("%randomgradient%%servername% - %mcversion%", "Another motd");
|
||||||
private boolean colorizeMotd = false;
|
private boolean colorizeMotd = false;
|
||||||
|
@ -4,74 +4,105 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class ArrayValueReader implements ValueReader {
|
public class ArrayValueReader implements ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
public static final ArrayValueReader ARRAY_VALUE_READER = new ArrayValueReader();
|
public static final ArrayValueReader ARRAY_VALUE_READER = new ArrayValueReader();
|
||||||
@Override
|
|
||||||
public boolean canRead(String s) {
|
|
||||||
return s.startsWith("[");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
public boolean canRead(String s)
|
||||||
AtomicInteger line = context.line;
|
{
|
||||||
int startLine = line.get();
|
return s.startsWith("[");
|
||||||
int startIndex = index.get();
|
}
|
||||||
List<Object> arrayItems = new ArrayList<Object>();
|
|
||||||
boolean terminated = false;
|
|
||||||
boolean inComment = false;
|
|
||||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
|
||||||
|
|
||||||
for (int i = index.incrementAndGet(); i < s.length(); i = index.incrementAndGet()) {
|
|
||||||
|
|
||||||
char c = s.charAt(i);
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
if (c == '#' && !inComment) {
|
{
|
||||||
inComment = true;
|
AtomicInteger line = context.line;
|
||||||
} else if (c == '\n') {
|
int startLine = line.get();
|
||||||
inComment = false;
|
int startIndex = index.get();
|
||||||
line.incrementAndGet();
|
List<Object> arrayItems = new ArrayList<Object>();
|
||||||
} else if (inComment || Character.isWhitespace(c) || c == ',') {
|
boolean terminated = false;
|
||||||
continue;
|
boolean inComment = false;
|
||||||
} else if (c == '[') {
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
Object converted = read(s, index, context);
|
|
||||||
if (converted instanceof dev.plex.toml.Results.Errors) {
|
for (int i = index.incrementAndGet(); i < s.length(); i = index.incrementAndGet())
|
||||||
errors.add((dev.plex.toml.Results.Errors) converted);
|
{
|
||||||
} else if (!isHomogenousArray(converted, arrayItems)) {
|
|
||||||
errors.heterogenous(context.identifier.getName(), line.get());
|
char c = s.charAt(i);
|
||||||
} else {
|
|
||||||
arrayItems.add(converted);
|
if (c == '#' && !inComment)
|
||||||
|
{
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
else if (c == '\n')
|
||||||
|
{
|
||||||
|
inComment = false;
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
else if (inComment || Character.isWhitespace(c) || c == ',')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == '[')
|
||||||
|
{
|
||||||
|
Object converted = read(s, index, context);
|
||||||
|
if (converted instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
errors.add((dev.plex.toml.Results.Errors)converted);
|
||||||
|
}
|
||||||
|
else if (!isHomogenousArray(converted, arrayItems))
|
||||||
|
{
|
||||||
|
errors.heterogenous(context.identifier.getName(), line.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arrayItems.add(converted);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == ']')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Object converted = ValueReaders.VALUE_READERS.convert(s, index, context);
|
||||||
|
if (converted instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
errors.add((dev.plex.toml.Results.Errors)converted);
|
||||||
|
}
|
||||||
|
else if (!isHomogenousArray(converted, arrayItems))
|
||||||
|
{
|
||||||
|
errors.heterogenous(context.identifier.getName(), line.get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arrayItems.add(converted);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
} else if (c == ']') {
|
|
||||||
terminated = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
Object converted = ValueReaders.VALUE_READERS.convert(s, index, context);
|
|
||||||
if (converted instanceof dev.plex.toml.Results.Errors) {
|
|
||||||
errors.add((dev.plex.toml.Results.Errors) converted);
|
|
||||||
} else if (!isHomogenousArray(converted, arrayItems)) {
|
|
||||||
errors.heterogenous(context.identifier.getName(), line.get());
|
|
||||||
} else {
|
|
||||||
arrayItems.add(converted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!terminated) {
|
|
||||||
errors.unterminated(context.identifier.getName(), s.substring(startIndex, s.length()), startLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
return arrayItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isHomogenousArray(Object o, List<?> values) {
|
if (!terminated)
|
||||||
return values.isEmpty() || values.get(0).getClass().isAssignableFrom(o.getClass()) || o.getClass().isAssignableFrom(values.get(0).getClass());
|
{
|
||||||
}
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex), startLine);
|
||||||
|
}
|
||||||
private ArrayValueReader() {}
|
|
||||||
|
if (errors.hasErrors())
|
||||||
|
{
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrayItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isHomogenousArray(Object o, List<?> values)
|
||||||
|
{
|
||||||
|
return values.isEmpty() || values.get(0).getClass().isAssignableFrom(o.getClass()) || o.getClass().isAssignableFrom(values.get(0).getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,63 +4,79 @@ package dev.plex.toml;
|
|||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static dev.plex.toml.ValueWriters.WRITERS;
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||||
|
|
||||||
public abstract class ArrayValueWriter implements dev.plex.toml.ValueWriter
|
public abstract class ArrayValueWriter implements dev.plex.toml.ValueWriter
|
||||||
{
|
{
|
||||||
static protected boolean isArrayish(Object value) {
|
static protected boolean isArrayish(Object value)
|
||||||
return value instanceof Collection || value.getClass().isArray();
|
{
|
||||||
}
|
return value instanceof Collection || value.getClass().isArray();
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrimitiveType() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isArrayOfPrimitive(Object array) {
|
|
||||||
Object first = peek(array);
|
|
||||||
if (first != null) {
|
|
||||||
dev.plex.toml.ValueWriter valueWriter = WRITERS.findWriterFor(first);
|
|
||||||
return valueWriter.isPrimitiveType() || isArrayish(first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
@SuppressWarnings("unchecked")
|
return false;
|
||||||
protected Collection<?> normalize(Object value) {
|
|
||||||
Collection<Object> collection;
|
|
||||||
|
|
||||||
if (value.getClass().isArray()) {
|
|
||||||
// Arrays.asList() interprets an array as a single element,
|
|
||||||
// so convert it to a list by hand
|
|
||||||
collection = new ArrayList<Object>(Array.getLength(value));
|
|
||||||
for (int i = 0; i < Array.getLength(value); i++) {
|
|
||||||
Object elem = Array.get(value, i);
|
|
||||||
collection.add(elem);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
collection = (Collection<Object>) value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
static boolean isArrayOfPrimitive(Object array)
|
||||||
}
|
{
|
||||||
|
Object first = peek(array);
|
||||||
|
if (first != null)
|
||||||
|
{
|
||||||
|
dev.plex.toml.ValueWriter valueWriter = WRITERS.findWriterFor(first);
|
||||||
|
return valueWriter.isPrimitiveType() || isArrayish(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected Collection<?> normalize(Object value)
|
||||||
|
{
|
||||||
|
Collection<Object> collection;
|
||||||
|
|
||||||
|
if (value.getClass().isArray())
|
||||||
|
{
|
||||||
|
// Arrays.asList() interprets an array as a single element,
|
||||||
|
// so convert it to a list by hand
|
||||||
|
collection = new ArrayList<Object>(Array.getLength(value));
|
||||||
|
for (int i = 0; i < Array.getLength(value); i++)
|
||||||
|
{
|
||||||
|
Object elem = Array.get(value, i);
|
||||||
|
collection.add(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
collection = (Collection<Object>)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object peek(Object value)
|
||||||
|
{
|
||||||
|
if (value.getClass().isArray())
|
||||||
|
{
|
||||||
|
if (Array.getLength(value) > 0)
|
||||||
|
{
|
||||||
|
return Array.get(value, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Collection<?> collection = (Collection<?>)value;
|
||||||
|
if (collection.size() > 0)
|
||||||
|
{
|
||||||
|
return collection.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Object peek(Object value) {
|
|
||||||
if (value.getClass().isArray()) {
|
|
||||||
if (Array.getLength(value) > 0) {
|
|
||||||
return Array.get(value, 0);
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Collection<?> collection = (Collection<?>) value;
|
|
||||||
if (collection.size() > 0) {
|
|
||||||
return collection.iterator().next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,46 +3,55 @@ package dev.plex.toml;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
||||||
class BooleanValueReaderWriter implements ValueReader, ValueWriter {
|
class BooleanValueReaderWriter implements ValueReader, ValueWriter
|
||||||
|
{
|
||||||
static final BooleanValueReaderWriter BOOLEAN_VALUE_READER_WRITER = new BooleanValueReaderWriter();
|
|
||||||
|
|
||||||
@Override
|
static final BooleanValueReaderWriter BOOLEAN_VALUE_READER_WRITER = new BooleanValueReaderWriter();
|
||||||
public boolean canRead(String s) {
|
|
||||||
return s.startsWith("true") || s.startsWith("false");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(String s, AtomicInteger index, Context context) {
|
public boolean canRead(String s)
|
||||||
s = s.substring(index.get());
|
{
|
||||||
Boolean b = s.startsWith("true") ? Boolean.TRUE : Boolean.FALSE;
|
return s.startsWith("true") || s.startsWith("false");
|
||||||
|
}
|
||||||
int endIndex = b == Boolean.TRUE ? 4 : 5;
|
|
||||||
|
|
||||||
index.addAndGet(endIndex - 1);
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canWrite(Object value) {
|
public Object read(String s, AtomicInteger index, Context context)
|
||||||
return Boolean.class.isInstance(value);
|
{
|
||||||
}
|
s = s.substring(index.get());
|
||||||
|
Boolean b = s.startsWith("true") ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
|
||||||
@Override
|
int endIndex = b == Boolean.TRUE ? 4 : 5;
|
||||||
public void write(Object value, WriterContext context) {
|
|
||||||
context.write(value.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
index.addAndGet(endIndex - 1);
|
||||||
public boolean isPrimitiveType() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BooleanValueReaderWriter() {}
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public boolean canWrite(Object value)
|
||||||
return "boolean";
|
{
|
||||||
}
|
return value instanceof Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
context.write(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BooleanValueReaderWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "boolean";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,118 +5,148 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class Container {
|
public abstract class Container
|
||||||
|
{
|
||||||
|
|
||||||
abstract boolean accepts(String key);
|
abstract boolean accepts(String key);
|
||||||
abstract void put(String key, Object value);
|
|
||||||
abstract Object get(String key);
|
|
||||||
abstract boolean isImplicit();
|
|
||||||
|
|
||||||
static class Table extends Container {
|
abstract void put(String key, Object value);
|
||||||
private final Map<String, Object> values = new HashMap<String, Object>();
|
|
||||||
final String name;
|
|
||||||
final boolean implicit;
|
|
||||||
|
|
||||||
Table() {
|
abstract Object get(String key);
|
||||||
this(null, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Table(String name) {
|
|
||||||
this(name, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Table(String tableName, boolean implicit) {
|
abstract boolean isImplicit();
|
||||||
this.name = tableName;
|
|
||||||
this.implicit = implicit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
static class Table extends Container
|
||||||
boolean accepts(String key) {
|
{
|
||||||
return !values.containsKey(key) || values.get(key) instanceof TableArray;
|
private final Map<String, Object> values = new HashMap<String, Object>();
|
||||||
}
|
final String name;
|
||||||
|
final boolean implicit;
|
||||||
|
|
||||||
@Override
|
Table()
|
||||||
void put(String key, Object value) {
|
{
|
||||||
values.put(key, value);
|
this(null, false);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Object get(String key) {
|
|
||||||
return values.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isImplicit() {
|
|
||||||
return implicit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This modifies the Table's internal data structure, such that it is no longer usable.
|
|
||||||
*
|
|
||||||
* Therefore, this method must only be called when all data has been gathered.
|
|
||||||
|
|
||||||
* @return A Map-and-List-based of the TOML data
|
|
||||||
*/
|
|
||||||
Map<String, Object> consume() {
|
|
||||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
|
||||||
if (entry.getValue() instanceof Table) {
|
|
||||||
entry.setValue(((Table) entry.getValue()).consume());
|
|
||||||
} else if (entry.getValue() instanceof TableArray) {
|
|
||||||
entry.setValue(((TableArray) entry.getValue()).getValues());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return values;
|
public Table(String name)
|
||||||
|
{
|
||||||
|
this(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table(String tableName, boolean implicit)
|
||||||
|
{
|
||||||
|
this.name = tableName;
|
||||||
|
this.implicit = implicit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean accepts(String key)
|
||||||
|
{
|
||||||
|
return !values.containsKey(key) || values.get(key) instanceof TableArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void put(String key, Object value)
|
||||||
|
{
|
||||||
|
values.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Object get(String key)
|
||||||
|
{
|
||||||
|
return values.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isImplicit()
|
||||||
|
{
|
||||||
|
return implicit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This modifies the Table's internal data structure, such that it is no longer usable.
|
||||||
|
* <p>
|
||||||
|
* Therefore, this method must only be called when all data has been gathered.
|
||||||
|
*
|
||||||
|
* @return A Map-and-List-based of the TOML data
|
||||||
|
*/
|
||||||
|
Map<String, Object> consume()
|
||||||
|
{
|
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet())
|
||||||
|
{
|
||||||
|
if (entry.getValue() instanceof Table)
|
||||||
|
{
|
||||||
|
entry.setValue(((Table)entry.getValue()).consume());
|
||||||
|
}
|
||||||
|
else if (entry.getValue() instanceof TableArray)
|
||||||
|
{
|
||||||
|
entry.setValue(((TableArray)entry.getValue()).getValues());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return values.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
static class TableArray extends Container
|
||||||
public String toString() {
|
{
|
||||||
return values.toString();
|
private final List<Table> values = new ArrayList<Table>();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TableArray extends Container {
|
TableArray()
|
||||||
private final List<Table> values = new ArrayList<Table>();
|
{
|
||||||
|
values.add(new Table());
|
||||||
|
}
|
||||||
|
|
||||||
TableArray() {
|
@Override
|
||||||
values.add(new Table());
|
boolean accepts(String key)
|
||||||
|
{
|
||||||
|
return getCurrent().accepts(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void put(String key, Object value)
|
||||||
|
{
|
||||||
|
values.add((Table)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Object get(String key)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isImplicit()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, Object>> getValues()
|
||||||
|
{
|
||||||
|
ArrayList<Map<String, Object>> unwrappedValues = new ArrayList<Map<String, Object>>();
|
||||||
|
for (Table table : values)
|
||||||
|
{
|
||||||
|
unwrappedValues.add(table.consume());
|
||||||
|
}
|
||||||
|
return unwrappedValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
Table getCurrent()
|
||||||
|
{
|
||||||
|
return values.get(values.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return values.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Container()
|
||||||
boolean accepts(String key) {
|
{
|
||||||
return getCurrent().accepts(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
void put(String key, Object value) {
|
|
||||||
values.add((Table) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Object get(String key) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isImplicit() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Map<String, Object>> getValues() {
|
|
||||||
ArrayList<Map<String, Object>> unwrappedValues = new ArrayList<Map<String,Object>>();
|
|
||||||
for (Table table : values) {
|
|
||||||
unwrappedValues.add(table.consume());
|
|
||||||
}
|
|
||||||
return unwrappedValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
Table getCurrent() {
|
|
||||||
return values.get(values.size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return values.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Container() {}
|
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,21 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class Context {
|
public class Context
|
||||||
final dev.plex.toml.Identifier identifier;
|
{
|
||||||
final AtomicInteger line;
|
final dev.plex.toml.Identifier identifier;
|
||||||
final Results.Errors errors;
|
final AtomicInteger line;
|
||||||
|
final Results.Errors errors;
|
||||||
public Context(dev.plex.toml.Identifier identifier, AtomicInteger line, Results.Errors errors) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.line = line;
|
|
||||||
this.errors = errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Context with(dev.plex.toml.Identifier identifier) {
|
public Context(dev.plex.toml.Identifier identifier, AtomicInteger line, Results.Errors errors)
|
||||||
return new Context(identifier, line, errors);
|
{
|
||||||
}
|
this.identifier = identifier;
|
||||||
|
this.line = line;
|
||||||
|
this.errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Context with(dev.plex.toml.Identifier identifier)
|
||||||
|
{
|
||||||
|
return new Context(identifier, line, errors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,25 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class DatePolicy {
|
public class DatePolicy
|
||||||
|
{
|
||||||
|
|
||||||
private final TimeZone timeZone;
|
private final TimeZone timeZone;
|
||||||
private final boolean showFractionalSeconds;
|
private final boolean showFractionalSeconds;
|
||||||
|
|
||||||
DatePolicy(TimeZone timeZone, boolean showFractionalSeconds) {
|
|
||||||
this.timeZone = timeZone;
|
|
||||||
this.showFractionalSeconds = showFractionalSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeZone getTimeZone() {
|
DatePolicy(TimeZone timeZone, boolean showFractionalSeconds)
|
||||||
return timeZone;
|
{
|
||||||
}
|
this.timeZone = timeZone;
|
||||||
|
this.showFractionalSeconds = showFractionalSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isShowFractionalSeconds() {
|
TimeZone getTimeZone()
|
||||||
return showFractionalSeconds;
|
{
|
||||||
}
|
return timeZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isShowFractionalSeconds()
|
||||||
|
{
|
||||||
|
return showFractionalSeconds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,154 +7,198 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DateValueReaderWriter implements ValueReader, ValueWriter {
|
public class DateValueReaderWriter implements ValueReader, ValueWriter
|
||||||
|
{
|
||||||
|
|
||||||
static final DateValueReaderWriter DATE_VALUE_READER_WRITER = new DateValueReaderWriter();
|
static final DateValueReaderWriter DATE_VALUE_READER_WRITER = new DateValueReaderWriter();
|
||||||
static final DateValueReaderWriter DATE_PARSER_JDK_6 = new DateConverterJdk6();
|
static final DateValueReaderWriter DATE_PARSER_JDK_6 = new DateConverterJdk6();
|
||||||
private static final Pattern DATE_REGEX = Pattern.compile("(\\d{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9])(\\.\\d*)?(Z|(?:[+\\-]\\d{2}:\\d{2}))(.*)");
|
private static final Pattern DATE_REGEX = Pattern.compile("(\\d{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9])(\\.\\d*)?(Z|(?:[+\\-]\\d{2}:\\d{2}))(.*)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRead(String s) {
|
public boolean canRead(String s)
|
||||||
if (s.length() < 5) {
|
{
|
||||||
return false;
|
if (s.length() < 5)
|
||||||
}
|
{
|
||||||
|
return false;
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
char c = s.charAt(i);
|
|
||||||
|
|
||||||
if (i < 4) {
|
|
||||||
if (!Character.isDigit(c)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (c != '-') {
|
|
||||||
return false;
|
for (int i = 0; i < 5; i++)
|
||||||
}
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (i < 4)
|
||||||
|
{
|
||||||
|
if (!Character.isDigit(c))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c != '-')
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object read(String original, AtomicInteger index, Context context) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = index.get(); i < original.length(); i = index.incrementAndGet()) {
|
|
||||||
char c = original.charAt(i);
|
|
||||||
if (Character.isDigit(c) || c == '-' || c == '+' || c == ':' || c == '.' || c == 'T' || c == 'Z') {
|
|
||||||
sb.append(c);
|
|
||||||
} else {
|
|
||||||
index.decrementAndGet();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String s = sb.toString();
|
|
||||||
Matcher matcher = DATE_REGEX.matcher(s);
|
|
||||||
|
|
||||||
if (!matcher.matches()) {
|
|
||||||
Results.Errors errors = new Results.Errors();
|
|
||||||
errors.invalidValue(context.identifier.getName(), s, context.line.get());
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
String dateString = matcher.group(1);
|
|
||||||
String zone = matcher.group(3);
|
|
||||||
String fractionalSeconds = matcher.group(2);
|
|
||||||
String format = "yyyy-MM-dd'T'HH:mm:ss";
|
|
||||||
if (fractionalSeconds != null && !fractionalSeconds.isEmpty()) {
|
|
||||||
format += ".SSS";
|
|
||||||
dateString += fractionalSeconds;
|
|
||||||
}
|
|
||||||
format += "Z";
|
|
||||||
if ("Z".equals(zone)) {
|
|
||||||
dateString += "+0000";
|
|
||||||
} else if (zone.contains(":")) {
|
|
||||||
dateString += zone.replace(":", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
|
|
||||||
dateFormat.setLenient(false);
|
|
||||||
return dateFormat.parse(dateString);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Results.Errors errors = new Results.Errors();
|
|
||||||
errors.invalidValue(context.identifier.getName(), s, context.line.get());
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canWrite(Object value) {
|
|
||||||
return value instanceof Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(Object value, WriterContext context) {
|
|
||||||
DateFormat formatter = getFormatter(context.getDatePolicy());
|
|
||||||
context.write(formatter.format(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrimitiveType() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateFormat getFormatter(DatePolicy datePolicy) {
|
|
||||||
boolean utc = "UTC".equals(datePolicy.getTimeZone().getID());
|
|
||||||
String format;
|
|
||||||
|
|
||||||
if (utc && datePolicy.isShowFractionalSeconds()) {
|
|
||||||
format = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
|
||||||
} else if (utc) {
|
|
||||||
format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
|
||||||
} else if (datePolicy.isShowFractionalSeconds()) {
|
|
||||||
format = getTimeZoneAndFractionalSecondsFormat();
|
|
||||||
} else {
|
|
||||||
format = getTimeZoneFormat();
|
|
||||||
}
|
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat(format);
|
|
||||||
formatter.setTimeZone(datePolicy.getTimeZone());
|
|
||||||
|
|
||||||
return formatter;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getTimeZoneFormat() {
|
|
||||||
return "yyyy-MM-dd'T'HH:mm:ssXXX";
|
|
||||||
}
|
|
||||||
|
|
||||||
String getTimeZoneAndFractionalSecondsFormat() {
|
|
||||||
return "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateValueReaderWriter() {}
|
|
||||||
|
|
||||||
private static class DateConverterJdk6 extends DateValueReaderWriter {
|
|
||||||
@Override
|
@Override
|
||||||
public void write(Object value, WriterContext context) {
|
public Object read(String original, AtomicInteger index, Context context)
|
||||||
DateFormat formatter = super.getFormatter(context.getDatePolicy());
|
{
|
||||||
String date = formatter.format(value);
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if ("UTC".equals(context.getDatePolicy().getTimeZone().getID())) {
|
|
||||||
context.write(date);
|
|
||||||
} else {
|
|
||||||
int insertionIndex = date.length() - 2;
|
|
||||||
context.write(date.substring(0, insertionIndex)).write(':').write(date.substring(insertionIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getTimeZoneAndFractionalSecondsFormat() {
|
|
||||||
return "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getTimeZoneFormat() {
|
|
||||||
return "yyyy-MM-dd'T'HH:mm:ssZ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
for (int i = index.get(); i < original.length(); i = index.incrementAndGet())
|
||||||
public String toString() {
|
{
|
||||||
return "datetime";
|
char c = original.charAt(i);
|
||||||
}
|
if (Character.isDigit(c) || c == '-' || c == '+' || c == ':' || c == '.' || c == 'T' || c == 'Z')
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index.decrementAndGet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = sb.toString();
|
||||||
|
Matcher matcher = DATE_REGEX.matcher(s);
|
||||||
|
|
||||||
|
if (!matcher.matches())
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), s, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
String dateString = matcher.group(1);
|
||||||
|
String zone = matcher.group(3);
|
||||||
|
String fractionalSeconds = matcher.group(2);
|
||||||
|
String format = "yyyy-MM-dd'T'HH:mm:ss";
|
||||||
|
if (fractionalSeconds != null && !fractionalSeconds.isEmpty())
|
||||||
|
{
|
||||||
|
format += ".SSS";
|
||||||
|
dateString += fractionalSeconds;
|
||||||
|
}
|
||||||
|
format += "Z";
|
||||||
|
if ("Z".equals(zone))
|
||||||
|
{
|
||||||
|
dateString += "+0000";
|
||||||
|
}
|
||||||
|
else if (zone.contains(":"))
|
||||||
|
{
|
||||||
|
dateString += zone.replace(":", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
|
||||||
|
dateFormat.setLenient(false);
|
||||||
|
return dateFormat.parse(dateString);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), s, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
DateFormat formatter = getFormatter(context.getDatePolicy());
|
||||||
|
context.write(formatter.format(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateFormat getFormatter(DatePolicy datePolicy)
|
||||||
|
{
|
||||||
|
boolean utc = "UTC".equals(datePolicy.getTimeZone().getID());
|
||||||
|
String format;
|
||||||
|
|
||||||
|
if (utc && datePolicy.isShowFractionalSeconds())
|
||||||
|
{
|
||||||
|
format = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
|
}
|
||||||
|
else if (utc)
|
||||||
|
{
|
||||||
|
format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||||
|
}
|
||||||
|
else if (datePolicy.isShowFractionalSeconds())
|
||||||
|
{
|
||||||
|
format = getTimeZoneAndFractionalSecondsFormat();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format = getTimeZoneFormat();
|
||||||
|
}
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(format);
|
||||||
|
formatter.setTimeZone(datePolicy.getTimeZone());
|
||||||
|
|
||||||
|
return formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTimeZoneFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ssXXX";
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTimeZoneAndFractionalSecondsFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateValueReaderWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateConverterJdk6 extends DateValueReaderWriter
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
DateFormat formatter = super.getFormatter(context.getDatePolicy());
|
||||||
|
String date = formatter.format(value);
|
||||||
|
|
||||||
|
if ("UTC".equals(context.getDatePolicy().getTimeZone().getID()))
|
||||||
|
{
|
||||||
|
context.write(date);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int insertionIndex = date.length() - 2;
|
||||||
|
context.write(date.substring(0, insertionIndex)).write(':').write(date.substring(insertionIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getTimeZoneAndFractionalSecondsFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getTimeZoneFormat()
|
||||||
|
{
|
||||||
|
return "yyyy-MM-dd'T'HH:mm:ssZ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "datetime";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,13 @@ public class Identifier
|
|||||||
{
|
{
|
||||||
type = Type.TABLE_ARRAY;
|
type = Type.TABLE_ARRAY;
|
||||||
valid = isValidTableArray(name, context);
|
valid = isValidTableArray(name, context);
|
||||||
} else if (name.startsWith("["))
|
}
|
||||||
|
else if (name.startsWith("["))
|
||||||
{
|
{
|
||||||
type = Type.TABLE;
|
type = Type.TABLE;
|
||||||
valid = isValidTable(name, context);
|
valid = isValidTable(name, context);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
type = Type.KEY;
|
type = Type.KEY;
|
||||||
valid = isValidKey(name, context);
|
valid = isValidKey(name, context);
|
||||||
@ -78,9 +80,9 @@ public class Identifier
|
|||||||
return type == Type.TABLE_ARRAY;
|
return type == Type.TABLE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum Type
|
private enum Type
|
||||||
{
|
{
|
||||||
KEY, TABLE, TABLE_ARRAY;
|
KEY, TABLE, TABLE_ARRAY
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String extractName(String raw)
|
private static String extractName(String raw)
|
||||||
@ -95,7 +97,8 @@ public class Identifier
|
|||||||
{
|
{
|
||||||
quoted = !quoted;
|
quoted = !quoted;
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
} else if (quoted || !Character.isWhitespace(c))
|
}
|
||||||
|
else if (quoted || !Character.isWhitespace(c))
|
||||||
{
|
{
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
@ -125,7 +128,8 @@ public class Identifier
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
quoted = !quoted;
|
quoted = !quoted;
|
||||||
} else if (!quoted && (ALLOWED_CHARS.indexOf(c) == -1))
|
}
|
||||||
|
else if (!quoted && (ALLOWED_CHARS.indexOf(c) == -1))
|
||||||
{
|
{
|
||||||
context.errors.invalidKey(name, context.line.get());
|
context.errors.invalidKey(name, context.line.get());
|
||||||
return false;
|
return false;
|
||||||
@ -137,12 +141,7 @@ public class Identifier
|
|||||||
|
|
||||||
private static boolean isValidTable(String name, Context context)
|
private static boolean isValidTable(String name, Context context)
|
||||||
{
|
{
|
||||||
boolean valid = true;
|
boolean valid = name.endsWith("]");
|
||||||
|
|
||||||
if (!name.endsWith("]"))
|
|
||||||
{
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String trimmed = name.substring(1, name.length() - 1).trim();
|
String trimmed = name.substring(1, name.length() - 1).trim();
|
||||||
if (trimmed.isEmpty() || trimmed.charAt(0) == '.' || trimmed.endsWith("."))
|
if (trimmed.isEmpty() || trimmed.charAt(0) == '.' || trimmed.endsWith("."))
|
||||||
@ -175,32 +174,38 @@ public class Identifier
|
|||||||
if (!quoteAllowed)
|
if (!quoteAllowed)
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
} else if (quoted && trimmed.charAt(i - 1) != '\\')
|
}
|
||||||
|
else if (quoted && trimmed.charAt(i - 1) != '\\')
|
||||||
{
|
{
|
||||||
charAllowed = false;
|
charAllowed = false;
|
||||||
dotAllowed = true;
|
dotAllowed = true;
|
||||||
quoteAllowed = false;
|
quoteAllowed = false;
|
||||||
} else if (!quoted)
|
}
|
||||||
|
else if (!quoted)
|
||||||
{
|
{
|
||||||
quoted = true;
|
quoted = true;
|
||||||
quoteAllowed = true;
|
quoteAllowed = true;
|
||||||
}
|
}
|
||||||
} else if (quoted)
|
}
|
||||||
|
else if (quoted)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
} else if (c == '.')
|
}
|
||||||
|
else if (c == '.')
|
||||||
{
|
{
|
||||||
if (dotAllowed)
|
if (dotAllowed)
|
||||||
{
|
{
|
||||||
charAllowed = true;
|
charAllowed = true;
|
||||||
dotAllowed = false;
|
dotAllowed = false;
|
||||||
quoteAllowed = true;
|
quoteAllowed = true;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
context.errors.emptyImplicitTable(name, context.line.get());
|
context.errors.emptyImplicitTable(name, context.line.get());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (Character.isWhitespace(c))
|
}
|
||||||
|
else if (Character.isWhitespace(c))
|
||||||
{
|
{
|
||||||
char prev = trimmed.charAt(i - 1);
|
char prev = trimmed.charAt(i - 1);
|
||||||
if (!Character.isWhitespace(prev) && prev != '.')
|
if (!Character.isWhitespace(prev) && prev != '.')
|
||||||
@ -209,14 +214,16 @@ public class Identifier
|
|||||||
dotAllowed = true;
|
dotAllowed = true;
|
||||||
quoteAllowed = true;
|
quoteAllowed = true;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (charAllowed && ALLOWED_CHARS.indexOf(c) > -1)
|
if (charAllowed && ALLOWED_CHARS.indexOf(c) > -1)
|
||||||
{
|
{
|
||||||
charAllowed = true;
|
charAllowed = true;
|
||||||
dotAllowed = true;
|
dotAllowed = true;
|
||||||
quoteAllowed = false;
|
quoteAllowed = false;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
@ -234,12 +241,7 @@ public class Identifier
|
|||||||
|
|
||||||
private static boolean isValidTableArray(String line, Context context)
|
private static boolean isValidTableArray(String line, Context context)
|
||||||
{
|
{
|
||||||
boolean valid = true;
|
boolean valid = line.endsWith("]]");
|
||||||
|
|
||||||
if (!line.endsWith("]]"))
|
|
||||||
{
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String trimmed = line.substring(2, line.length() - 2).trim();
|
String trimmed = line.substring(2, line.length() - 2).trim();
|
||||||
if (trimmed.isEmpty() || trimmed.charAt(0) == '.' || trimmed.endsWith("."))
|
if (trimmed.isEmpty() || trimmed.charAt(0) == '.' || trimmed.endsWith("."))
|
||||||
@ -272,32 +274,38 @@ public class Identifier
|
|||||||
if (!quoteAllowed)
|
if (!quoteAllowed)
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
} else if (quoted && trimmed.charAt(i - 1) != '\\')
|
}
|
||||||
|
else if (quoted && trimmed.charAt(i - 1) != '\\')
|
||||||
{
|
{
|
||||||
charAllowed = false;
|
charAllowed = false;
|
||||||
dotAllowed = true;
|
dotAllowed = true;
|
||||||
quoteAllowed = false;
|
quoteAllowed = false;
|
||||||
} else if (!quoted)
|
}
|
||||||
|
else if (!quoted)
|
||||||
{
|
{
|
||||||
quoted = true;
|
quoted = true;
|
||||||
quoteAllowed = true;
|
quoteAllowed = true;
|
||||||
}
|
}
|
||||||
} else if (quoted)
|
}
|
||||||
|
else if (quoted)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
} else if (c == '.')
|
}
|
||||||
|
else if (c == '.')
|
||||||
{
|
{
|
||||||
if (dotAllowed)
|
if (dotAllowed)
|
||||||
{
|
{
|
||||||
charAllowed = true;
|
charAllowed = true;
|
||||||
dotAllowed = false;
|
dotAllowed = false;
|
||||||
quoteAllowed = true;
|
quoteAllowed = true;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
context.errors.emptyImplicitTable(line, context.line.get());
|
context.errors.emptyImplicitTable(line, context.line.get());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (Character.isWhitespace(c))
|
}
|
||||||
|
else if (Character.isWhitespace(c))
|
||||||
{
|
{
|
||||||
char prev = trimmed.charAt(i - 1);
|
char prev = trimmed.charAt(i - 1);
|
||||||
if (!Character.isWhitespace(prev) && prev != '.' && prev != '"')
|
if (!Character.isWhitespace(prev) && prev != '.' && prev != '"')
|
||||||
@ -306,14 +314,16 @@ public class Identifier
|
|||||||
dotAllowed = true;
|
dotAllowed = true;
|
||||||
quoteAllowed = true;
|
quoteAllowed = true;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (charAllowed && ALLOWED_CHARS.indexOf(c) > -1)
|
if (charAllowed && ALLOWED_CHARS.indexOf(c) > -1)
|
||||||
{
|
{
|
||||||
charAllowed = true;
|
charAllowed = true;
|
||||||
dotAllowed = true;
|
dotAllowed = true;
|
||||||
quoteAllowed = false;
|
quoteAllowed = false;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
@ -2,61 +2,87 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class IdentifierConverter {
|
public class IdentifierConverter
|
||||||
|
{
|
||||||
static final IdentifierConverter IDENTIFIER_CONVERTER = new IdentifierConverter();
|
|
||||||
|
|
||||||
Identifier convert(String s, AtomicInteger index, Context context) {
|
static final IdentifierConverter IDENTIFIER_CONVERTER = new IdentifierConverter();
|
||||||
boolean quoted = false;
|
|
||||||
StringBuilder name = new StringBuilder();
|
Identifier convert(String s, AtomicInteger index, Context context)
|
||||||
boolean terminated = false;
|
{
|
||||||
boolean isKey = s.charAt(index.get()) != '[';
|
boolean quoted = false;
|
||||||
boolean isTableArray = !isKey && s.length() > index.get() + 1 && s.charAt(index.get() + 1) == '[';
|
StringBuilder name = new StringBuilder();
|
||||||
boolean inComment = false;
|
boolean terminated = false;
|
||||||
|
boolean isKey = s.charAt(index.get()) != '[';
|
||||||
for (int i = index.get(); i < s.length(); i = index.incrementAndGet()) {
|
boolean isTableArray = !isKey && s.length() > index.get() + 1 && s.charAt(index.get() + 1) == '[';
|
||||||
char c = s.charAt(i);
|
boolean inComment = false;
|
||||||
if (Keys.isQuote(c) && (i == 0 || s.charAt(i - 1) != '\\')) {
|
|
||||||
quoted = !quoted;
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
name.append(c);
|
{
|
||||||
} else if (c == '\n') {
|
char c = s.charAt(i);
|
||||||
index.decrementAndGet();
|
if (Keys.isQuote(c) && (i == 0 || s.charAt(i - 1) != '\\'))
|
||||||
break;
|
{
|
||||||
} else if (quoted) {
|
quoted = !quoted;
|
||||||
name.append(c);
|
name.append(c);
|
||||||
} else if (c == '=' && isKey) {
|
}
|
||||||
terminated = true;
|
else if (c == '\n')
|
||||||
break;
|
{
|
||||||
} else if (c == ']' && !isKey) {
|
index.decrementAndGet();
|
||||||
if (!isTableArray || s.length() > index.get() + 1 && s.charAt(index.get() + 1) == ']') {
|
break;
|
||||||
terminated = true;
|
}
|
||||||
name.append(']');
|
else if (quoted)
|
||||||
if (isTableArray) {
|
{
|
||||||
name.append(']');
|
name.append(c);
|
||||||
}
|
}
|
||||||
|
else if (c == '=' && isKey)
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (c == ']' && !isKey)
|
||||||
|
{
|
||||||
|
if (!isTableArray || s.length() > index.get() + 1 && s.charAt(index.get() + 1) == ']')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
name.append(']');
|
||||||
|
if (isTableArray)
|
||||||
|
{
|
||||||
|
name.append(']');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (terminated && c == '#')
|
||||||
|
{
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
else if (terminated && !Character.isWhitespace(c) && !inComment)
|
||||||
|
{
|
||||||
|
terminated = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!terminated)
|
||||||
|
{
|
||||||
|
name.append(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (terminated && c == '#') {
|
|
||||||
inComment = true;
|
if (!terminated)
|
||||||
} else if (terminated && !Character.isWhitespace(c) && !inComment) {
|
{
|
||||||
terminated = false;
|
if (isKey)
|
||||||
break;
|
{
|
||||||
} else if (!terminated) {
|
context.errors.unterminatedKey(name.toString(), context.line.get());
|
||||||
name.append(c);
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
context.errors.invalidKey(name.toString(), context.line.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Identifier.INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Identifier.from(name.toString(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!terminated) {
|
private IdentifierConverter()
|
||||||
if (isKey) {
|
{
|
||||||
context.errors.unterminatedKey(name.toString(), context.line.get());
|
|
||||||
} else {
|
|
||||||
context.errors.invalidKey(name.toString(), context.line.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Identifier.INVALID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Identifier.from(name.toString(), context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IdentifierConverter() {}
|
|
||||||
}
|
}
|
||||||
|
@ -2,29 +2,34 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls how a {@link TomlWriter} indents tables and key/value pairs.
|
* Controls how a {@link TomlWriter} indents tables and key/value pairs.
|
||||||
*
|
* <p>
|
||||||
* The default policy is to not indent.
|
* The default policy is to not indent.
|
||||||
*/
|
*/
|
||||||
public class IndentationPolicy {
|
public class IndentationPolicy
|
||||||
private final int tableIndent;
|
{
|
||||||
private final int keyValueIndent;
|
private final int tableIndent;
|
||||||
private final int arrayDelimiterPadding;
|
private final int keyValueIndent;
|
||||||
|
private final int arrayDelimiterPadding;
|
||||||
|
|
||||||
IndentationPolicy(int keyIndentation, int tableIndentation, int arrayDelimiterPadding) {
|
IndentationPolicy(int keyIndentation, int tableIndentation, int arrayDelimiterPadding)
|
||||||
this.keyValueIndent = keyIndentation;
|
{
|
||||||
this.tableIndent = tableIndentation;
|
this.keyValueIndent = keyIndentation;
|
||||||
this.arrayDelimiterPadding = arrayDelimiterPadding;
|
this.tableIndent = tableIndentation;
|
||||||
}
|
this.arrayDelimiterPadding = arrayDelimiterPadding;
|
||||||
|
}
|
||||||
|
|
||||||
int getTableIndent() {
|
int getTableIndent()
|
||||||
return tableIndent;
|
{
|
||||||
}
|
return tableIndent;
|
||||||
|
}
|
||||||
|
|
||||||
int getKeyValueIndent() {
|
int getKeyValueIndent()
|
||||||
return keyValueIndent;
|
{
|
||||||
}
|
return keyValueIndent;
|
||||||
|
}
|
||||||
|
|
||||||
int getArrayDelimiterPadding() {
|
int getArrayDelimiterPadding()
|
||||||
return arrayDelimiterPadding;
|
{
|
||||||
}
|
return arrayDelimiterPadding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,71 +6,89 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
class InlineTableValueReader implements dev.plex.toml.ValueReader
|
class InlineTableValueReader implements dev.plex.toml.ValueReader
|
||||||
{
|
{
|
||||||
|
|
||||||
static final InlineTableValueReader INLINE_TABLE_VALUE_READER = new InlineTableValueReader();
|
static final InlineTableValueReader INLINE_TABLE_VALUE_READER = new InlineTableValueReader();
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRead(String s) {
|
|
||||||
return s.startsWith("{");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(String s, AtomicInteger sharedIndex, dev.plex.toml.Context context) {
|
public boolean canRead(String s)
|
||||||
AtomicInteger line = context.line;
|
{
|
||||||
int startLine = line.get();
|
return s.startsWith("{");
|
||||||
int startIndex = sharedIndex.get();
|
|
||||||
boolean inKey = true;
|
|
||||||
boolean inValue = false;
|
|
||||||
boolean terminated = false;
|
|
||||||
StringBuilder currentKey = new StringBuilder();
|
|
||||||
HashMap<String, Object> results = new HashMap<String, Object>();
|
|
||||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
|
||||||
|
|
||||||
for (int i = sharedIndex.incrementAndGet(); sharedIndex.get() < s.length(); i = sharedIndex.incrementAndGet()) {
|
|
||||||
char c = s.charAt(i);
|
|
||||||
|
|
||||||
if (inValue && !Character.isWhitespace(c)) {
|
|
||||||
Object converted = dev.plex.toml.ValueReaders.VALUE_READERS.convert(s, sharedIndex, context.with(dev.plex.toml.Identifier.from(currentKey.toString(), context)));
|
|
||||||
|
|
||||||
if (converted instanceof dev.plex.toml.Results.Errors) {
|
|
||||||
errors.add((dev.plex.toml.Results.Errors) converted);
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
String currentKeyTrimmed = currentKey.toString().trim();
|
|
||||||
Object previous = results.put(currentKeyTrimmed, converted);
|
|
||||||
|
|
||||||
if (previous != null) {
|
|
||||||
errors.duplicateKey(currentKeyTrimmed, context.line.get());
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentKey = new StringBuilder();
|
|
||||||
inValue = false;
|
|
||||||
} else if (c == ',') {
|
|
||||||
inKey = true;
|
|
||||||
inValue = false;
|
|
||||||
currentKey = new StringBuilder();
|
|
||||||
} else if (c == '=') {
|
|
||||||
inKey = false;
|
|
||||||
inValue = true;
|
|
||||||
} else if (c == '}') {
|
|
||||||
terminated = true;
|
|
||||||
break;
|
|
||||||
} else if (inKey) {
|
|
||||||
currentKey.append(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!terminated) {
|
|
||||||
errors.unterminated(context.identifier.getName(), s.substring(startIndex), startLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private InlineTableValueReader() {}
|
@Override
|
||||||
|
public Object read(String s, AtomicInteger sharedIndex, dev.plex.toml.Context context)
|
||||||
|
{
|
||||||
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int startIndex = sharedIndex.get();
|
||||||
|
boolean inKey = true;
|
||||||
|
boolean inValue = false;
|
||||||
|
boolean terminated = false;
|
||||||
|
StringBuilder currentKey = new StringBuilder();
|
||||||
|
HashMap<String, Object> results = new HashMap<String, Object>();
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
|
||||||
|
for (int i = sharedIndex.incrementAndGet(); sharedIndex.get() < s.length(); i = sharedIndex.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (inValue && !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
Object converted = dev.plex.toml.ValueReaders.VALUE_READERS.convert(s, sharedIndex, context.with(dev.plex.toml.Identifier.from(currentKey.toString(), context)));
|
||||||
|
|
||||||
|
if (converted instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
errors.add((dev.plex.toml.Results.Errors)converted);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
String currentKeyTrimmed = currentKey.toString().trim();
|
||||||
|
Object previous = results.put(currentKeyTrimmed, converted);
|
||||||
|
|
||||||
|
if (previous != null)
|
||||||
|
{
|
||||||
|
errors.duplicateKey(currentKeyTrimmed, context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentKey = new StringBuilder();
|
||||||
|
inValue = false;
|
||||||
|
}
|
||||||
|
else if (c == ',')
|
||||||
|
{
|
||||||
|
inKey = true;
|
||||||
|
inValue = false;
|
||||||
|
currentKey = new StringBuilder();
|
||||||
|
}
|
||||||
|
else if (c == '=')
|
||||||
|
{
|
||||||
|
inKey = false;
|
||||||
|
inValue = true;
|
||||||
|
}
|
||||||
|
else if (c == '}')
|
||||||
|
{
|
||||||
|
terminated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (inKey)
|
||||||
|
{
|
||||||
|
currentKey.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!terminated)
|
||||||
|
{
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex), startLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.hasErrors())
|
||||||
|
{
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InlineTableValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,67 +3,84 @@ package dev.plex.toml;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class Keys {
|
class Keys
|
||||||
|
{
|
||||||
static class Key {
|
|
||||||
final String name;
|
|
||||||
final int index;
|
|
||||||
final String path;
|
|
||||||
|
|
||||||
Key(String name, int index, Key next) {
|
static class Key
|
||||||
this.name = name;
|
{
|
||||||
this.index = index;
|
final String name;
|
||||||
if (next != null) {
|
final int index;
|
||||||
this.path = name + "." + next.path;
|
final String path;
|
||||||
} else {
|
|
||||||
this.path = name;
|
Key(String name, int index, Key next)
|
||||||
}
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.index = index;
|
||||||
|
if (next != null)
|
||||||
|
{
|
||||||
|
this.path = name + "." + next.path;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.path = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static Key[] split(String key) {
|
static Key[] split(String key)
|
||||||
List<Key> splitKey = new ArrayList<Key>();
|
{
|
||||||
StringBuilder current = new StringBuilder();
|
List<Key> splitKey = new ArrayList<Key>();
|
||||||
boolean quoted = false;
|
StringBuilder current = new StringBuilder();
|
||||||
boolean indexable = true;
|
boolean quoted = false;
|
||||||
boolean inIndex = false;
|
boolean indexable = true;
|
||||||
int index = -1;
|
boolean inIndex = false;
|
||||||
|
int index = -1;
|
||||||
for (int i = key.length() - 1; i > -1; i--) {
|
|
||||||
char c = key.charAt(i);
|
for (int i = key.length() - 1; i > -1; i--)
|
||||||
if (c == ']' && indexable) {
|
{
|
||||||
inIndex = true;
|
char c = key.charAt(i);
|
||||||
continue;
|
if (c == ']' && indexable)
|
||||||
}
|
{
|
||||||
indexable = false;
|
inIndex = true;
|
||||||
if (c == '[' && inIndex) {
|
continue;
|
||||||
inIndex = false;
|
}
|
||||||
index = Integer.parseInt(current.toString());
|
indexable = false;
|
||||||
current = new StringBuilder();
|
if (c == '[' && inIndex)
|
||||||
continue;
|
{
|
||||||
}
|
inIndex = false;
|
||||||
if (isQuote(c) && (i == 0 || key.charAt(i - 1) != '\\')) {
|
index = Integer.parseInt(current.toString());
|
||||||
quoted = !quoted;
|
current = new StringBuilder();
|
||||||
indexable = false;
|
continue;
|
||||||
}
|
}
|
||||||
if (c != '.' || quoted) {
|
if (isQuote(c) && (i == 0 || key.charAt(i - 1) != '\\'))
|
||||||
current.insert(0, c);
|
{
|
||||||
} else {
|
quoted = !quoted;
|
||||||
|
indexable = false;
|
||||||
|
}
|
||||||
|
if (c != '.' || quoted)
|
||||||
|
{
|
||||||
|
current.insert(0, c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
||||||
|
indexable = true;
|
||||||
|
index = -1;
|
||||||
|
current = new StringBuilder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
||||||
indexable = true;
|
|
||||||
index = -1;
|
|
||||||
current = new StringBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
|
||||||
|
|
||||||
return splitKey.toArray(new Key[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isQuote(char c) {
|
|
||||||
return c == '"' || c == '\'';
|
|
||||||
}
|
|
||||||
|
|
||||||
private Keys() {}
|
return splitKey.toArray(new Key[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isQuote(char c)
|
||||||
|
{
|
||||||
|
return c == '"' || c == '\'';
|
||||||
|
}
|
||||||
|
|
||||||
|
private Keys()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public class LiteralStringValueReader implements ValueReader
|
public class LiteralStringValueReader implements ValueReader
|
||||||
{
|
{
|
||||||
public static final LiteralStringValueReader LITERAL_STRING_VALUE_READER = new LiteralStringValueReader();
|
public static final LiteralStringValueReader LITERAL_STRING_VALUE_READER = new LiteralStringValueReader();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRead(String s)
|
public boolean canRead(String s)
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ class MapValueWriter implements dev.plex.toml.ValueWriter
|
|||||||
file = context.file;
|
file = context.file;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<?, ?> from = (Map<?, ?>) value;
|
Map<?, ?> from = (Map<?, ?>)value;
|
||||||
|
|
||||||
Toml toml = null;
|
Toml toml = null;
|
||||||
|
|
||||||
@ -46,7 +46,8 @@ class MapValueWriter implements dev.plex.toml.ValueWriter
|
|||||||
{
|
{
|
||||||
context.writeKey();
|
context.writeKey();
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
context.writeKey();
|
context.writeKey();
|
||||||
}
|
}
|
||||||
@ -70,8 +71,14 @@ class MapValueWriter implements dev.plex.toml.ValueWriter
|
|||||||
{
|
{
|
||||||
if (context.key != null)
|
if (context.key != null)
|
||||||
{
|
{
|
||||||
if (key.toString().equalsIgnoreCase(context.key)) continue;
|
if (key.toString().equalsIgnoreCase(context.key))
|
||||||
if (toml.contains(context.key + "." + key)) continue;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (toml.contains(context.key + "." + key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +89,8 @@ class MapValueWriter implements dev.plex.toml.ValueWriter
|
|||||||
context.write(quoteKey(key)).write(" = ");
|
context.write(quoteKey(key)).write(" = ");
|
||||||
valueWriter.write(fromValue, context);
|
valueWriter.write(fromValue, context);
|
||||||
context.write('\n');
|
context.write('\n');
|
||||||
} else if (valueWriter == dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER)
|
}
|
||||||
|
else if (valueWriter == dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER)
|
||||||
{
|
{
|
||||||
context.indent();
|
context.indent();
|
||||||
context.setArrayKey(key.toString());
|
context.setArrayKey(key.toString());
|
||||||
@ -105,8 +113,14 @@ class MapValueWriter implements dev.plex.toml.ValueWriter
|
|||||||
{
|
{
|
||||||
if (context.key != null)
|
if (context.key != null)
|
||||||
{
|
{
|
||||||
if (key.toString().equalsIgnoreCase(context.key)) continue;
|
if (key.toString().equalsIgnoreCase(context.key))
|
||||||
if (toml.contains(context.key + "." + key)) continue;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (toml.contains(context.key + "." + key))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,49 +4,58 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
class MultilineLiteralStringValueReader implements ValueReader
|
class MultilineLiteralStringValueReader implements ValueReader
|
||||||
{
|
{
|
||||||
|
|
||||||
static final MultilineLiteralStringValueReader MULTILINE_LITERAL_STRING_VALUE_READER = new MultilineLiteralStringValueReader();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRead(String s) {
|
|
||||||
return s.startsWith("'''");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
static final MultilineLiteralStringValueReader MULTILINE_LITERAL_STRING_VALUE_READER = new MultilineLiteralStringValueReader();
|
||||||
public Object read(String s, AtomicInteger index, Context context) {
|
|
||||||
AtomicInteger line = context.line;
|
|
||||||
int startLine = line.get();
|
|
||||||
int originalStartIndex = index.get();
|
|
||||||
int startIndex = index.addAndGet(3);
|
|
||||||
int endIndex = -1;
|
|
||||||
|
|
||||||
if (s.charAt(startIndex) == '\n') {
|
|
||||||
startIndex = index.incrementAndGet();
|
|
||||||
line.incrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = startIndex; i < s.length(); i = index.incrementAndGet()) {
|
|
||||||
char c = s.charAt(i);
|
|
||||||
|
|
||||||
if (c == '\n') {
|
@Override
|
||||||
line.incrementAndGet();
|
public boolean canRead(String s)
|
||||||
}
|
{
|
||||||
|
return s.startsWith("'''");
|
||||||
if (c == '\'' && s.length() > i + 2 && s.charAt(i + 1) == '\'' && s.charAt(i + 2) == '\'') {
|
|
||||||
endIndex = i;
|
|
||||||
index.addAndGet(2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (endIndex == -1) {
|
|
||||||
Results.Errors errors = new Results.Errors();
|
|
||||||
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
|
||||||
return errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.substring(startIndex, endIndex);
|
@Override
|
||||||
}
|
public Object read(String s, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int originalStartIndex = index.get();
|
||||||
|
int startIndex = index.addAndGet(3);
|
||||||
|
int endIndex = -1;
|
||||||
|
|
||||||
private MultilineLiteralStringValueReader() {}
|
if (s.charAt(startIndex) == '\n')
|
||||||
|
{
|
||||||
|
startIndex = index.incrementAndGet();
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = startIndex; i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '\'' && s.length() > i + 2 && s.charAt(i + 1) == '\'' && s.charAt(i + 2) == '\'')
|
||||||
|
{
|
||||||
|
endIndex = i;
|
||||||
|
index.addAndGet(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex == -1)
|
||||||
|
{
|
||||||
|
Results.Errors errors = new Results.Errors();
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.substring(startIndex, endIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MultilineLiteralStringValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,53 +5,62 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
class MultilineStringValueReader implements ValueReader
|
class MultilineStringValueReader implements ValueReader
|
||||||
{
|
{
|
||||||
|
|
||||||
static final MultilineStringValueReader MULTILINE_STRING_VALUE_READER = new MultilineStringValueReader();
|
static final MultilineStringValueReader MULTILINE_STRING_VALUE_READER = new MultilineStringValueReader();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRead(String s) {
|
public boolean canRead(String s)
|
||||||
return s.startsWith("\"\"\"");
|
{
|
||||||
}
|
return s.startsWith("\"\"\"");
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
|
||||||
AtomicInteger line = context.line;
|
|
||||||
int startLine = line.get();
|
|
||||||
int originalStartIndex = index.get();
|
|
||||||
int startIndex = index.addAndGet(3);
|
|
||||||
int endIndex = -1;
|
|
||||||
|
|
||||||
if (s.charAt(startIndex) == '\n') {
|
|
||||||
startIndex = index.incrementAndGet();
|
|
||||||
line.incrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = startIndex; i < s.length(); i = index.incrementAndGet()) {
|
|
||||||
char c = s.charAt(i);
|
|
||||||
|
|
||||||
if (c == '\n') {
|
|
||||||
line.incrementAndGet();
|
|
||||||
} else if (c == '"' && s.length() > i + 2 && s.charAt(i + 1) == '"' && s.charAt(i + 2) == '"') {
|
|
||||||
endIndex = i;
|
|
||||||
index.addAndGet(2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (endIndex == -1) {
|
|
||||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
|
||||||
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
|
||||||
return errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s = s.substring(startIndex, endIndex);
|
@Override
|
||||||
s = s.replaceAll("\\\\\\s+", "");
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(s);
|
{
|
||||||
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceSpecialCharacters(s);
|
AtomicInteger line = context.line;
|
||||||
|
int startLine = line.get();
|
||||||
|
int originalStartIndex = index.get();
|
||||||
|
int startIndex = index.addAndGet(3);
|
||||||
|
int endIndex = -1;
|
||||||
|
|
||||||
return s;
|
if (s.charAt(startIndex) == '\n')
|
||||||
}
|
{
|
||||||
|
startIndex = index.incrementAndGet();
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
private MultilineStringValueReader() {
|
for (int i = startIndex; i < s.length(); i = index.incrementAndGet())
|
||||||
}
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
else if (c == '"' && s.length() > i + 2 && s.charAt(i + 1) == '"' && s.charAt(i + 2) == '"')
|
||||||
|
{
|
||||||
|
endIndex = i;
|
||||||
|
index.addAndGet(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIndex == -1)
|
||||||
|
{
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = s.substring(startIndex, endIndex);
|
||||||
|
s = s.replaceAll("\\\\\\s+", "");
|
||||||
|
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(s);
|
||||||
|
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceSpecialCharacters(s);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MultilineStringValueReader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,103 +4,131 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
class NumberValueReaderWriter implements dev.plex.toml.ValueReader, dev.plex.toml.ValueWriter
|
class NumberValueReaderWriter implements dev.plex.toml.ValueReader, dev.plex.toml.ValueWriter
|
||||||
{
|
{
|
||||||
static final NumberValueReaderWriter NUMBER_VALUE_READER_WRITER = new NumberValueReaderWriter();
|
static final NumberValueReaderWriter NUMBER_VALUE_READER_WRITER = new NumberValueReaderWriter();
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRead(String s) {
|
|
||||||
char firstChar = s.charAt(0);
|
|
||||||
|
|
||||||
return firstChar == '+' || firstChar == '-' || Character.isDigit(firstChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
public boolean canRead(String s)
|
||||||
boolean signable = true;
|
{
|
||||||
boolean dottable = false;
|
char firstChar = s.charAt(0);
|
||||||
boolean exponentable = false;
|
|
||||||
boolean terminatable = false;
|
|
||||||
boolean underscorable = false;
|
|
||||||
String type = "";
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = index.get(); i < s.length(); i = index.incrementAndGet()) {
|
return firstChar == '+' || firstChar == '-' || Character.isDigit(firstChar);
|
||||||
char c = s.charAt(i);
|
|
||||||
boolean notLastChar = s.length() > i + 1;
|
|
||||||
|
|
||||||
if (Character.isDigit(c)) {
|
|
||||||
sb.append(c);
|
|
||||||
signable = false;
|
|
||||||
terminatable = true;
|
|
||||||
if (type.isEmpty()) {
|
|
||||||
type = "integer";
|
|
||||||
dottable = true;
|
|
||||||
}
|
|
||||||
underscorable = notLastChar;
|
|
||||||
exponentable = !type.equals("exponent");
|
|
||||||
} else if ((c == '+' || c == '-') && signable && notLastChar) {
|
|
||||||
signable = false;
|
|
||||||
terminatable = false;
|
|
||||||
if (c == '-') {
|
|
||||||
sb.append('-');
|
|
||||||
}
|
|
||||||
} else if (c == '.' && dottable && notLastChar) {
|
|
||||||
sb.append('.');
|
|
||||||
type = "float";
|
|
||||||
terminatable = false;
|
|
||||||
dottable = false;
|
|
||||||
exponentable = false;
|
|
||||||
underscorable = false;
|
|
||||||
} else if ((c == 'E' || c == 'e') && exponentable && notLastChar) {
|
|
||||||
sb.append('E');
|
|
||||||
type = "exponent";
|
|
||||||
terminatable = false;
|
|
||||||
signable = true;
|
|
||||||
dottable = false;
|
|
||||||
exponentable = false;
|
|
||||||
underscorable = false;
|
|
||||||
} else if (c == '_' && underscorable && notLastChar && Character.isDigit(s.charAt(i + 1))) {
|
|
||||||
underscorable = false;
|
|
||||||
} else {
|
|
||||||
if (!terminatable) {
|
|
||||||
type = "";
|
|
||||||
}
|
|
||||||
index.decrementAndGet();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.equals("integer")) {
|
@Override
|
||||||
return Long.valueOf(sb.toString());
|
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
} else if (type.equals("float")) {
|
{
|
||||||
return Double.valueOf(sb.toString());
|
boolean signable = true;
|
||||||
} else if (type.equals("exponent")) {
|
boolean dottable = false;
|
||||||
String[] exponentString = sb.toString().split("E");
|
boolean exponentable = false;
|
||||||
|
boolean terminatable = false;
|
||||||
return Double.parseDouble(exponentString[0]) * Math.pow(10, Double.parseDouble(exponentString[1]));
|
boolean underscorable = false;
|
||||||
} else {
|
String type = "";
|
||||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
StringBuilder sb = new StringBuilder();
|
||||||
errors.invalidValue(context.identifier.getName(), sb.toString(), context.line.get());
|
|
||||||
return errors;
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
|
{
|
||||||
|
char c = s.charAt(i);
|
||||||
|
boolean notLastChar = s.length() > i + 1;
|
||||||
|
|
||||||
|
if (Character.isDigit(c))
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
signable = false;
|
||||||
|
terminatable = true;
|
||||||
|
if (type.isEmpty())
|
||||||
|
{
|
||||||
|
type = "integer";
|
||||||
|
dottable = true;
|
||||||
|
}
|
||||||
|
underscorable = notLastChar;
|
||||||
|
exponentable = !type.equals("exponent");
|
||||||
|
}
|
||||||
|
else if ((c == '+' || c == '-') && signable && notLastChar)
|
||||||
|
{
|
||||||
|
signable = false;
|
||||||
|
terminatable = false;
|
||||||
|
if (c == '-')
|
||||||
|
{
|
||||||
|
sb.append('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '.' && dottable && notLastChar)
|
||||||
|
{
|
||||||
|
sb.append('.');
|
||||||
|
type = "float";
|
||||||
|
terminatable = false;
|
||||||
|
dottable = false;
|
||||||
|
exponentable = false;
|
||||||
|
underscorable = false;
|
||||||
|
}
|
||||||
|
else if ((c == 'E' || c == 'e') && exponentable && notLastChar)
|
||||||
|
{
|
||||||
|
sb.append('E');
|
||||||
|
type = "exponent";
|
||||||
|
terminatable = false;
|
||||||
|
signable = true;
|
||||||
|
dottable = false;
|
||||||
|
exponentable = false;
|
||||||
|
underscorable = false;
|
||||||
|
}
|
||||||
|
else if (c == '_' && underscorable && notLastChar && Character.isDigit(s.charAt(i + 1)))
|
||||||
|
{
|
||||||
|
underscorable = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!terminatable)
|
||||||
|
{
|
||||||
|
type = "";
|
||||||
|
}
|
||||||
|
index.decrementAndGet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("integer"))
|
||||||
|
{
|
||||||
|
return Long.valueOf(sb.toString());
|
||||||
|
}
|
||||||
|
else if (type.equals("float"))
|
||||||
|
{
|
||||||
|
return Double.valueOf(sb.toString());
|
||||||
|
}
|
||||||
|
else if (type.equals("exponent"))
|
||||||
|
{
|
||||||
|
String[] exponentString = sb.toString().split("E");
|
||||||
|
|
||||||
|
return Double.parseDouble(exponentString[0]) * Math.pow(10, Double.parseDouble(exponentString[1]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), sb.toString(), context.line.get());
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canWrite(Object value) {
|
public boolean canWrite(Object value)
|
||||||
return Number.class.isInstance(value);
|
{
|
||||||
}
|
return value instanceof Number;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(Object value, dev.plex.toml.WriterContext context) {
|
public void write(Object value, dev.plex.toml.WriterContext context)
|
||||||
context.write(value.toString());
|
{
|
||||||
}
|
context.write(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPrimitiveType() {
|
public boolean isPrimitiveType()
|
||||||
return true;
|
{
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
return "number";
|
{
|
||||||
}
|
return "number";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
class ObjectValueWriter implements ValueWriter
|
class ObjectValueWriter implements ValueWriter
|
||||||
{
|
{
|
||||||
@ -26,7 +30,9 @@ class ObjectValueWriter implements ValueWriter
|
|||||||
if (field.isAnnotationPresent(SerializedName.class))
|
if (field.isAnnotationPresent(SerializedName.class))
|
||||||
{
|
{
|
||||||
to.put(field.getDeclaredAnnotation(SerializedName.class).value(), getFieldValue(field, value));
|
to.put(field.getDeclaredAnnotation(SerializedName.class).value(), getFieldValue(field, value));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
to.put(field.getName(), getFieldValue(field, value));
|
to.put(field.getName(), getFieldValue(field, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +80,8 @@ class ObjectValueWriter implements ValueWriter
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
value = field.get(o);
|
value = field.get(o);
|
||||||
} catch (IllegalAccessException ignored)
|
}
|
||||||
|
catch (IllegalAccessException ignored)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
field.setAccessible(isAccessible);
|
field.setAccessible(isAccessible);
|
||||||
|
@ -4,50 +4,60 @@ import java.util.Collection;
|
|||||||
|
|
||||||
class PrimitiveArrayValueWriter extends ArrayValueWriter
|
class PrimitiveArrayValueWriter extends ArrayValueWriter
|
||||||
{
|
{
|
||||||
static final ValueWriter PRIMITIVE_ARRAY_VALUE_WRITER = new PrimitiveArrayValueWriter();
|
static final ValueWriter PRIMITIVE_ARRAY_VALUE_WRITER = new PrimitiveArrayValueWriter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canWrite(Object value) {
|
public boolean canWrite(Object value)
|
||||||
return isArrayish(value) && isArrayOfPrimitive(value);
|
{
|
||||||
}
|
return isArrayish(value) && isArrayOfPrimitive(value);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(Object o, WriterContext context) {
|
|
||||||
Collection<?> values = normalize(o);
|
|
||||||
|
|
||||||
context.write('[');
|
|
||||||
context.writeArrayDelimiterPadding();
|
|
||||||
|
|
||||||
boolean first = true;
|
|
||||||
ValueWriter firstWriter = null;
|
|
||||||
|
|
||||||
for (Object value : values) {
|
|
||||||
if (first) {
|
|
||||||
firstWriter = ValueWriters.WRITERS.findWriterFor(value);
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
ValueWriter writer = ValueWriters.WRITERS.findWriterFor(value);
|
|
||||||
if (writer != firstWriter) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
context.getContextPath() +
|
|
||||||
": cannot write a heterogeneous array; first element was of type " + firstWriter +
|
|
||||||
" but found " + writer
|
|
||||||
);
|
|
||||||
}
|
|
||||||
context.write(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueWriters.WRITERS.findWriterFor(value).write(value, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.writeArrayDelimiterPadding();
|
@Override
|
||||||
context.write(']');
|
public void write(Object o, WriterContext context)
|
||||||
}
|
{
|
||||||
|
Collection<?> values = normalize(o);
|
||||||
|
|
||||||
private PrimitiveArrayValueWriter() {}
|
context.write('[');
|
||||||
|
context.writeArrayDelimiterPadding();
|
||||||
|
|
||||||
@Override
|
boolean first = true;
|
||||||
public String toString() {
|
ValueWriter firstWriter = null;
|
||||||
return "primitive-array";
|
|
||||||
}
|
for (Object value : values)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
firstWriter = ValueWriters.WRITERS.findWriterFor(value);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ValueWriter writer = ValueWriters.WRITERS.findWriterFor(value);
|
||||||
|
if (writer != firstWriter)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(
|
||||||
|
context.getContextPath() +
|
||||||
|
": cannot write a heterogeneous array; first element was of type " + firstWriter +
|
||||||
|
" but found " + writer
|
||||||
|
);
|
||||||
|
}
|
||||||
|
context.write(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueWriters.WRITERS.findWriterFor(value).write(value, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.writeArrayDelimiterPadding();
|
||||||
|
context.write(']');
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrimitiveArrayValueWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "primitive-array";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,290 +1,361 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
class Results {
|
class Results
|
||||||
|
{
|
||||||
static class Errors {
|
|
||||||
|
|
||||||
private final StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
void duplicateTable(String table, int line) {
|
|
||||||
sb.append("Duplicate table definition on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": [")
|
|
||||||
.append(table)
|
|
||||||
.append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tableDuplicatesKey(String table, AtomicInteger line) {
|
static class Errors
|
||||||
sb.append("Key already exists for table defined on line ")
|
{
|
||||||
.append(line.get())
|
|
||||||
.append(": [")
|
|
||||||
.append(table)
|
|
||||||
.append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void keyDuplicatesTable(String key, AtomicInteger line) {
|
private final StringBuilder sb = new StringBuilder();
|
||||||
sb.append("Table already exists for key defined on line ")
|
|
||||||
.append(line.get())
|
|
||||||
.append(": ")
|
|
||||||
.append(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void emptyImplicitTable(String table, int line) {
|
|
||||||
sb.append("Invalid table definition due to empty implicit table name: ")
|
|
||||||
.append(table);
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidTable(String table, int line) {
|
|
||||||
sb.append("Invalid table definition on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": ")
|
|
||||||
.append(table)
|
|
||||||
.append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
void duplicateKey(String key, int line) {
|
|
||||||
sb.append("Duplicate key");
|
|
||||||
if (line > -1) {
|
|
||||||
sb.append(" on line ")
|
|
||||||
.append(line);
|
|
||||||
}
|
|
||||||
sb.append(": ")
|
|
||||||
.append(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidTextAfterIdentifier(dev.plex.toml.Identifier identifier, char text, int line) {
|
|
||||||
sb.append("Invalid text after key ")
|
|
||||||
.append(identifier.getName())
|
|
||||||
.append(" on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(". Make sure to terminate the value or add a comment (#).");
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidKey(String key, int line) {
|
|
||||||
sb.append("Invalid key on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": ")
|
|
||||||
.append(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidTableArray(String tableArray, int line) {
|
|
||||||
sb.append("Invalid table array definition on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": ")
|
|
||||||
.append(tableArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidValue(String key, String value, int line) {
|
|
||||||
sb.append("Invalid value on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": ")
|
|
||||||
.append(key)
|
|
||||||
.append(" = ")
|
|
||||||
.append(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unterminatedKey(String key, int line) {
|
|
||||||
sb.append("Key is not followed by an equals sign on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": ")
|
|
||||||
.append(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unterminated(String key, String value, int line) {
|
|
||||||
sb.append("Unterminated value on line ")
|
|
||||||
.append(line)
|
|
||||||
.append(": ")
|
|
||||||
.append(key)
|
|
||||||
.append(" = ")
|
|
||||||
.append(value.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void heterogenous(String key, int line) {
|
void duplicateTable(String table, int line)
|
||||||
sb.append(key)
|
{
|
||||||
.append(" becomes a heterogeneous array on line ")
|
sb.append("Duplicate table definition on line ")
|
||||||
.append(line);
|
.append(line)
|
||||||
}
|
.append(": [")
|
||||||
|
.append(table)
|
||||||
boolean hasErrors() {
|
.append("]");
|
||||||
return sb.length() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Errors other) {
|
|
||||||
sb.append(other.sb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final Errors errors = new Errors();
|
|
||||||
private final Set<String> tables = new HashSet<String>();
|
|
||||||
private final Deque<Container> stack = new ArrayDeque<Container>();
|
|
||||||
|
|
||||||
Results() {
|
|
||||||
stack.push(new Container.Table(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addValue(String key, Object value, AtomicInteger line) {
|
|
||||||
Container currentTable = stack.peek();
|
|
||||||
|
|
||||||
if (value instanceof Map) {
|
|
||||||
String path = getInlineTablePath(key);
|
|
||||||
if (path == null) {
|
|
||||||
startTable(key, line);
|
|
||||||
} else if (path.isEmpty()) {
|
|
||||||
startTables(dev.plex.toml.Identifier.from(key, null), line);
|
|
||||||
} else {
|
|
||||||
startTables(dev.plex.toml.Identifier.from(path, null), line);
|
|
||||||
}
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> valueMap = (Map<String, Object>) value;
|
|
||||||
for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
|
|
||||||
addValue(entry.getKey(), entry.getValue(), line);
|
|
||||||
}
|
|
||||||
stack.pop();
|
|
||||||
} else if (currentTable.accepts(key)) {
|
|
||||||
currentTable.put(key, value);
|
|
||||||
} else {
|
|
||||||
if (currentTable.get(key) instanceof Container) {
|
|
||||||
errors.keyDuplicatesTable(key, line);
|
|
||||||
} else {
|
|
||||||
errors.duplicateKey(key, line != null ? line.get() : -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void startTableArray(dev.plex.toml.Identifier identifier, AtomicInteger line) {
|
|
||||||
String tableName = identifier.getBareName();
|
|
||||||
while (stack.size() > 1) {
|
|
||||||
stack.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
|
||||||
for (int i = 0; i < tableParts.length; i++) {
|
|
||||||
String tablePart = tableParts[i].name;
|
|
||||||
Container currentContainer = stack.peek();
|
|
||||||
|
|
||||||
if (currentContainer.get(tablePart) instanceof Container.TableArray) {
|
|
||||||
Container.TableArray currentTableArray = (Container.TableArray) currentContainer.get(tablePart);
|
|
||||||
stack.push(currentTableArray);
|
|
||||||
|
|
||||||
if (i == tableParts.length - 1) {
|
|
||||||
currentTableArray.put(tablePart, new Container.Table());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push(currentTableArray.getCurrent());
|
public void tableDuplicatesKey(String table, AtomicInteger line)
|
||||||
currentContainer = stack.peek();
|
{
|
||||||
} else if (currentContainer.get(tablePart) instanceof Container.Table && i < tableParts.length - 1) {
|
sb.append("Key already exists for table defined on line ")
|
||||||
Container nextTable = (Container) currentContainer.get(tablePart);
|
.append(line.get())
|
||||||
stack.push(nextTable);
|
.append(": [")
|
||||||
} else if (currentContainer.accepts(tablePart)) {
|
.append(table)
|
||||||
Container newContainer = i == tableParts.length - 1 ? new Container.TableArray() : new Container.Table();
|
.append("]");
|
||||||
addValue(tablePart, newContainer, line);
|
|
||||||
stack.push(newContainer);
|
|
||||||
|
|
||||||
if (newContainer instanceof Container.TableArray) {
|
|
||||||
stack.push(((Container.TableArray) newContainer).getCurrent());
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errors.duplicateTable(tableName, line.get());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void startTables(dev.plex.toml.Identifier id, AtomicInteger line) {
|
public void keyDuplicatesTable(String key, AtomicInteger line)
|
||||||
String tableName = id.getBareName();
|
{
|
||||||
|
sb.append("Table already exists for key defined on line ")
|
||||||
while (stack.size() > 1) {
|
.append(line.get())
|
||||||
stack.pop();
|
.append(": ")
|
||||||
}
|
.append(key);
|
||||||
|
|
||||||
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
|
||||||
for (int i = 0; i < tableParts.length; i++) {
|
|
||||||
String tablePart = tableParts[i].name;
|
|
||||||
Container currentContainer = stack.peek();
|
|
||||||
if (currentContainer.get(tablePart) instanceof Container) {
|
|
||||||
Container nextTable = (Container) currentContainer.get(tablePart);
|
|
||||||
if (i == tableParts.length - 1 && !nextTable.isImplicit()) {
|
|
||||||
errors.duplicateTable(tableName, line.get());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
stack.push(nextTable);
|
|
||||||
if (stack.peek() instanceof Container.TableArray) {
|
void emptyImplicitTable(String table, int line)
|
||||||
stack.push(((Container.TableArray) stack.peek()).getCurrent());
|
{
|
||||||
|
sb.append("Invalid table definition due to empty implicit table name: ")
|
||||||
|
.append(table);
|
||||||
}
|
}
|
||||||
} else if (currentContainer.accepts(tablePart)) {
|
|
||||||
startTable(tablePart, i < tableParts.length - 1, line);
|
|
||||||
} else {
|
|
||||||
errors.tableDuplicatesKey(tablePart, line);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
void invalidTable(String table, int line)
|
||||||
* Warning: After this method has been called, this instance is no longer usable.
|
{
|
||||||
*/
|
sb.append("Invalid table definition on line ")
|
||||||
Map<String, Object> consume() {
|
.append(line)
|
||||||
Container values = stack.getLast();
|
.append(": ")
|
||||||
stack.clear();
|
.append(table)
|
||||||
|
.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
return ((Container.Table) values).consume();
|
void duplicateKey(String key, int line)
|
||||||
}
|
{
|
||||||
|
sb.append("Duplicate key");
|
||||||
|
if (line > -1)
|
||||||
|
{
|
||||||
|
sb.append(" on line ")
|
||||||
|
.append(line);
|
||||||
|
}
|
||||||
|
sb.append(": ")
|
||||||
|
.append(key);
|
||||||
|
}
|
||||||
|
|
||||||
private Container startTable(String tableName, AtomicInteger line) {
|
void invalidTextAfterIdentifier(dev.plex.toml.Identifier identifier, char text, int line)
|
||||||
Container newTable = new Container.Table(tableName);
|
{
|
||||||
addValue(tableName, newTable, line);
|
sb.append("Invalid text after key ")
|
||||||
stack.push(newTable);
|
.append(identifier.getName())
|
||||||
|
.append(" on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(". Make sure to terminate the value or add a comment (#).");
|
||||||
|
}
|
||||||
|
|
||||||
return newTable;
|
void invalidKey(String key, int line)
|
||||||
}
|
{
|
||||||
|
sb.append("Invalid key on line ")
|
||||||
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(key);
|
||||||
|
}
|
||||||
|
|
||||||
private Container startTable(String tableName, boolean implicit, AtomicInteger line) {
|
void invalidTableArray(String tableArray, int line)
|
||||||
Container newTable = new Container.Table(tableName, implicit);
|
{
|
||||||
addValue(tableName, newTable, line);
|
sb.append("Invalid table array definition on line ")
|
||||||
stack.push(newTable);
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
|
.append(tableArray);
|
||||||
|
}
|
||||||
|
|
||||||
return newTable;
|
void invalidValue(String key, String value, int line)
|
||||||
}
|
{
|
||||||
|
sb.append("Invalid value on line ")
|
||||||
private String getInlineTablePath(String key) {
|
.append(line)
|
||||||
Iterator<Container> descendingIterator = stack.descendingIterator();
|
.append(": ")
|
||||||
StringBuilder sb = new StringBuilder();
|
.append(key)
|
||||||
|
.append(" = ")
|
||||||
while (descendingIterator.hasNext()) {
|
.append(value);
|
||||||
Container next = descendingIterator.next();
|
}
|
||||||
if (next instanceof Container.TableArray) {
|
|
||||||
return null;
|
void unterminatedKey(String key, int line)
|
||||||
}
|
{
|
||||||
|
sb.append("Key is not followed by an equals sign on line ")
|
||||||
Container.Table table = (Container.Table) next;
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
if (table.name == null) {
|
.append(key);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
void unterminated(String key, String value, int line)
|
||||||
if (sb.length() > 0) {
|
{
|
||||||
sb.append('.');
|
sb.append("Unterminated value on line ")
|
||||||
}
|
.append(line)
|
||||||
|
.append(": ")
|
||||||
sb.append(table.name);
|
.append(key)
|
||||||
}
|
.append(" = ")
|
||||||
|
.append(value.trim());
|
||||||
if (sb.length() > 0) {
|
}
|
||||||
sb.append('.');
|
|
||||||
|
public void heterogenous(String key, int line)
|
||||||
|
{
|
||||||
|
sb.append(key)
|
||||||
|
.append(" becomes a heterogeneous array on line ")
|
||||||
|
.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasErrors()
|
||||||
|
{
|
||||||
|
return sb.length() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Errors other)
|
||||||
|
{
|
||||||
|
sb.append(other.sb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(key)
|
final Errors errors = new Errors();
|
||||||
.insert(0, '[')
|
private final Set<String> tables = new HashSet<String>();
|
||||||
.append(']');
|
private final Deque<Container> stack = new ArrayDeque<Container>();
|
||||||
|
|
||||||
return sb.toString();
|
Results()
|
||||||
}
|
{
|
||||||
|
stack.push(new Container.Table(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
void addValue(String key, Object value, AtomicInteger line)
|
||||||
|
{
|
||||||
|
Container currentTable = stack.peek();
|
||||||
|
|
||||||
|
if (value instanceof Map)
|
||||||
|
{
|
||||||
|
String path = getInlineTablePath(key);
|
||||||
|
if (path == null)
|
||||||
|
{
|
||||||
|
startTable(key, line);
|
||||||
|
}
|
||||||
|
else if (path.isEmpty())
|
||||||
|
{
|
||||||
|
startTables(dev.plex.toml.Identifier.from(key, null), line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startTables(dev.plex.toml.Identifier.from(path, null), line);
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> valueMap = (Map<String, Object>)value;
|
||||||
|
for (Map.Entry<String, Object> entry : valueMap.entrySet())
|
||||||
|
{
|
||||||
|
addValue(entry.getKey(), entry.getValue(), line);
|
||||||
|
}
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
else if (currentTable.accepts(key))
|
||||||
|
{
|
||||||
|
currentTable.put(key, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (currentTable.get(key) instanceof Container)
|
||||||
|
{
|
||||||
|
errors.keyDuplicatesTable(key, line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.duplicateKey(key, line != null ? line.get() : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startTableArray(dev.plex.toml.Identifier identifier, AtomicInteger line)
|
||||||
|
{
|
||||||
|
String tableName = identifier.getBareName();
|
||||||
|
while (stack.size() > 1)
|
||||||
|
{
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
||||||
|
for (int i = 0; i < tableParts.length; i++)
|
||||||
|
{
|
||||||
|
String tablePart = tableParts[i].name;
|
||||||
|
Container currentContainer = stack.peek();
|
||||||
|
|
||||||
|
if (currentContainer.get(tablePart) instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
Container.TableArray currentTableArray = (Container.TableArray)currentContainer.get(tablePart);
|
||||||
|
stack.push(currentTableArray);
|
||||||
|
|
||||||
|
if (i == tableParts.length - 1)
|
||||||
|
{
|
||||||
|
currentTableArray.put(tablePart, new Container.Table());
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.push(currentTableArray.getCurrent());
|
||||||
|
currentContainer = stack.peek();
|
||||||
|
}
|
||||||
|
else if (currentContainer.get(tablePart) instanceof Container.Table && i < tableParts.length - 1)
|
||||||
|
{
|
||||||
|
Container nextTable = (Container)currentContainer.get(tablePart);
|
||||||
|
stack.push(nextTable);
|
||||||
|
}
|
||||||
|
else if (currentContainer.accepts(tablePart))
|
||||||
|
{
|
||||||
|
Container newContainer = i == tableParts.length - 1 ? new Container.TableArray() : new Container.Table();
|
||||||
|
addValue(tablePart, newContainer, line);
|
||||||
|
stack.push(newContainer);
|
||||||
|
|
||||||
|
if (newContainer instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
stack.push(((Container.TableArray)newContainer).getCurrent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.duplicateTable(tableName, line.get());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startTables(dev.plex.toml.Identifier id, AtomicInteger line)
|
||||||
|
{
|
||||||
|
String tableName = id.getBareName();
|
||||||
|
|
||||||
|
while (stack.size() > 1)
|
||||||
|
{
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
||||||
|
for (int i = 0; i < tableParts.length; i++)
|
||||||
|
{
|
||||||
|
String tablePart = tableParts[i].name;
|
||||||
|
Container currentContainer = stack.peek();
|
||||||
|
if (currentContainer.get(tablePart) instanceof Container)
|
||||||
|
{
|
||||||
|
Container nextTable = (Container)currentContainer.get(tablePart);
|
||||||
|
if (i == tableParts.length - 1 && !nextTable.isImplicit())
|
||||||
|
{
|
||||||
|
errors.duplicateTable(tableName, line.get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stack.push(nextTable);
|
||||||
|
if (stack.peek() instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
stack.push(((Container.TableArray)stack.peek()).getCurrent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (currentContainer.accepts(tablePart))
|
||||||
|
{
|
||||||
|
startTable(tablePart, i < tableParts.length - 1, line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.tableDuplicatesKey(tablePart, line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: After this method has been called, this instance is no longer usable.
|
||||||
|
*/
|
||||||
|
Map<String, Object> consume()
|
||||||
|
{
|
||||||
|
Container values = stack.getLast();
|
||||||
|
stack.clear();
|
||||||
|
|
||||||
|
return ((Container.Table)values).consume();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container startTable(String tableName, AtomicInteger line)
|
||||||
|
{
|
||||||
|
Container newTable = new Container.Table(tableName);
|
||||||
|
addValue(tableName, newTable, line);
|
||||||
|
stack.push(newTable);
|
||||||
|
|
||||||
|
return newTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container startTable(String tableName, boolean implicit, AtomicInteger line)
|
||||||
|
{
|
||||||
|
Container newTable = new Container.Table(tableName, implicit);
|
||||||
|
addValue(tableName, newTable, line);
|
||||||
|
stack.push(newTable);
|
||||||
|
|
||||||
|
return newTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getInlineTablePath(String key)
|
||||||
|
{
|
||||||
|
Iterator<Container> descendingIterator = stack.descendingIterator();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
while (descendingIterator.hasNext())
|
||||||
|
{
|
||||||
|
Container next = descendingIterator.next();
|
||||||
|
if (next instanceof Container.TableArray)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Container.Table table = (Container.Table)next;
|
||||||
|
|
||||||
|
if (table.name == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb.length() > 0)
|
||||||
|
{
|
||||||
|
sb.append('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(table.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb.length() > 0)
|
||||||
|
{
|
||||||
|
sb.append('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(key)
|
||||||
|
.insert(0, '[')
|
||||||
|
.append(']');
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,122 +8,147 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
class StringValueReaderWriter implements ValueReader, ValueWriter
|
class StringValueReaderWriter implements ValueReader, ValueWriter
|
||||||
{
|
{
|
||||||
|
|
||||||
static final StringValueReaderWriter STRING_VALUE_READER_WRITER = new StringValueReaderWriter();
|
|
||||||
private static final Pattern UNICODE_REGEX = Pattern.compile("\\\\[uU](.{4})");
|
|
||||||
|
|
||||||
static private final String[] specialCharacterEscapes = new String[93];
|
static final StringValueReaderWriter STRING_VALUE_READER_WRITER = new StringValueReaderWriter();
|
||||||
|
private static final Pattern UNICODE_REGEX = Pattern.compile("\\\\[uU](.{4})");
|
||||||
|
|
||||||
static {
|
static private final String[] specialCharacterEscapes = new String[93];
|
||||||
specialCharacterEscapes['\b'] = "\\b";
|
|
||||||
specialCharacterEscapes['\t'] = "\\t";
|
|
||||||
specialCharacterEscapes['\n'] = "\\n";
|
|
||||||
specialCharacterEscapes['\f'] = "\\f";
|
|
||||||
specialCharacterEscapes['\r'] = "\\r";
|
|
||||||
specialCharacterEscapes['"'] = "\\\"";
|
|
||||||
specialCharacterEscapes['\\'] = "\\\\";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
static
|
||||||
public boolean canRead(String s) {
|
{
|
||||||
return s.startsWith("\"");
|
specialCharacterEscapes['\b'] = "\\b";
|
||||||
}
|
specialCharacterEscapes['\t'] = "\\t";
|
||||||
|
specialCharacterEscapes['\n'] = "\\n";
|
||||||
@Override
|
specialCharacterEscapes['\f'] = "\\f";
|
||||||
public Object read(String s, AtomicInteger index, Context context) {
|
specialCharacterEscapes['\r'] = "\\r";
|
||||||
int startIndex = index.incrementAndGet();
|
specialCharacterEscapes['"'] = "\\\"";
|
||||||
int endIndex = -1;
|
specialCharacterEscapes['\\'] = "\\\\";
|
||||||
|
|
||||||
for (int i = index.get(); i < s.length(); i = index.incrementAndGet()) {
|
|
||||||
char ch = s.charAt(i);
|
|
||||||
if (ch == '"' && s.charAt(i - 1) != '\\') {
|
|
||||||
endIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endIndex == -1) {
|
@Override
|
||||||
Results.Errors errors = new Results.Errors();
|
public boolean canRead(String s)
|
||||||
errors.unterminated(context.identifier.getName(), s.substring(startIndex - 1), context.line.get());
|
{
|
||||||
return errors;
|
return s.startsWith("\"");
|
||||||
}
|
|
||||||
|
|
||||||
String raw = s.substring(startIndex, endIndex);
|
|
||||||
s = replaceUnicodeCharacters(raw);
|
|
||||||
s = replaceSpecialCharacters(s);
|
|
||||||
|
|
||||||
if (s == null) {
|
|
||||||
Results.Errors errors = new Results.Errors();
|
|
||||||
errors.invalidValue(context.identifier.getName(), raw, context.line.get());
|
|
||||||
return errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
@Override
|
||||||
}
|
public Object read(String s, AtomicInteger index, Context context)
|
||||||
|
{
|
||||||
|
int startIndex = index.incrementAndGet();
|
||||||
|
int endIndex = -1;
|
||||||
|
|
||||||
String replaceUnicodeCharacters(String value) {
|
for (int i = index.get(); i < s.length(); i = index.incrementAndGet())
|
||||||
Matcher unicodeMatcher = UNICODE_REGEX.matcher(value);
|
{
|
||||||
|
char ch = s.charAt(i);
|
||||||
|
if (ch == '"' && s.charAt(i - 1) != '\\')
|
||||||
|
{
|
||||||
|
endIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (unicodeMatcher.find()) {
|
if (endIndex == -1)
|
||||||
value = value.replace(unicodeMatcher.group(), new String(Character.toChars(Integer.parseInt(unicodeMatcher.group(1), 16))));
|
{
|
||||||
}
|
Results.Errors errors = new Results.Errors();
|
||||||
return value;
|
errors.unterminated(context.identifier.getName(), s.substring(startIndex - 1), context.line.get());
|
||||||
}
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
String replaceSpecialCharacters(String s) {
|
String raw = s.substring(startIndex, endIndex);
|
||||||
for (int i = 0; i < s.length() - 1; i++) {
|
s = replaceUnicodeCharacters(raw);
|
||||||
char ch = s.charAt(i);
|
s = replaceSpecialCharacters(s);
|
||||||
char next = s.charAt(i + 1);
|
|
||||||
|
|
||||||
if (ch == '\\' && next == '\\') {
|
if (s == null)
|
||||||
i++;
|
{
|
||||||
} else if (ch == '\\' && !(next == 'b' || next == 'f' || next == 'n' || next == 't' || next == 'r' || next == '"' || next == '\\')) {
|
Results.Errors errors = new Results.Errors();
|
||||||
return null;
|
errors.invalidValue(context.identifier.getName(), raw, context.line.get());
|
||||||
}
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.replace("\\n", "\n")
|
String replaceUnicodeCharacters(String value)
|
||||||
.replace("\\\"", "\"")
|
{
|
||||||
.replace("\\t", "\t")
|
Matcher unicodeMatcher = UNICODE_REGEX.matcher(value);
|
||||||
.replace("\\r", "\r")
|
|
||||||
.replace("\\\\", "\\")
|
|
||||||
.replace("\\/", "/")
|
|
||||||
.replace("\\b", "\b")
|
|
||||||
.replace("\\f", "\f");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
while (unicodeMatcher.find())
|
||||||
public boolean canWrite(Object value) {
|
{
|
||||||
return value instanceof String || value instanceof Character || value instanceof URL || value instanceof URI || value instanceof Enum;
|
value = value.replace(unicodeMatcher.group(), new String(Character.toChars(Integer.parseInt(unicodeMatcher.group(1), 16))));
|
||||||
}
|
}
|
||||||
|
return value;
|
||||||
@Override
|
|
||||||
public void write(Object value, WriterContext context) {
|
|
||||||
context.write('"');
|
|
||||||
escapeUnicode(value.toString(), context);
|
|
||||||
context.write('"');
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPrimitiveType() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void escapeUnicode(String in, WriterContext context) {
|
|
||||||
for (int i = 0; i < in.length(); i++) {
|
|
||||||
int codePoint = in.codePointAt(i);
|
|
||||||
if (codePoint < specialCharacterEscapes.length && specialCharacterEscapes[codePoint] != null) {
|
|
||||||
context.write(specialCharacterEscapes[codePoint]);
|
|
||||||
} else {
|
|
||||||
context.write(in.charAt(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private StringValueReaderWriter() {}
|
String replaceSpecialCharacters(String s)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < s.length() - 1; i++)
|
||||||
|
{
|
||||||
|
char ch = s.charAt(i);
|
||||||
|
char next = s.charAt(i + 1);
|
||||||
|
|
||||||
@Override
|
if (ch == '\\' && next == '\\')
|
||||||
public String toString() {
|
{
|
||||||
return "string";
|
i++;
|
||||||
}
|
}
|
||||||
|
else if (ch == '\\' && !(next == 'b' || next == 'f' || next == 'n' || next == 't' || next == 'r' || next == '"' || next == '\\'))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.replace("\\n", "\n")
|
||||||
|
.replace("\\\"", "\"")
|
||||||
|
.replace("\\t", "\t")
|
||||||
|
.replace("\\r", "\r")
|
||||||
|
.replace("\\\\", "\\")
|
||||||
|
.replace("\\/", "/")
|
||||||
|
.replace("\\b", "\b")
|
||||||
|
.replace("\\f", "\f");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canWrite(Object value)
|
||||||
|
{
|
||||||
|
return value instanceof String || value instanceof Character || value instanceof URL || value instanceof URI || value instanceof Enum;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Object value, WriterContext context)
|
||||||
|
{
|
||||||
|
context.write('"');
|
||||||
|
escapeUnicode(value.toString(), context);
|
||||||
|
context.write('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrimitiveType()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void escapeUnicode(String in, WriterContext context)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < in.length(); i++)
|
||||||
|
{
|
||||||
|
int codePoint = in.codePointAt(i);
|
||||||
|
if (codePoint < specialCharacterEscapes.length && specialCharacterEscapes[codePoint] != null)
|
||||||
|
{
|
||||||
|
context.write(specialCharacterEscapes[codePoint]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.write(in.charAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringValueReaderWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,38 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static dev.plex.toml.ValueWriters.WRITERS;
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||||
|
|
||||||
class TableArrayValueWriter extends ArrayValueWriter
|
class TableArrayValueWriter extends ArrayValueWriter
|
||||||
{
|
{
|
||||||
static final ValueWriter TABLE_ARRAY_VALUE_WRITER = new TableArrayValueWriter();
|
static final ValueWriter TABLE_ARRAY_VALUE_WRITER = new TableArrayValueWriter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canWrite(Object value) {
|
public boolean canWrite(Object value)
|
||||||
return isArrayish(value) && !isArrayOfPrimitive(value);
|
{
|
||||||
}
|
return isArrayish(value) && !isArrayOfPrimitive(value);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(Object from, WriterContext context) {
|
|
||||||
Collection<?> values = normalize(from);
|
|
||||||
|
|
||||||
WriterContext subContext = context.pushTableFromArray();
|
|
||||||
|
|
||||||
for (Object value : values) {
|
|
||||||
WRITERS.findWriterFor(value).write(value, subContext);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private TableArrayValueWriter() {}
|
@Override
|
||||||
|
public void write(Object from, WriterContext context)
|
||||||
|
{
|
||||||
|
Collection<?> values = normalize(from);
|
||||||
|
|
||||||
@Override
|
WriterContext subContext = context.pushTableFromArray();
|
||||||
public String toString() {
|
|
||||||
return "table-array";
|
for (Object value : values)
|
||||||
}
|
{
|
||||||
|
WRITERS.findWriterFor(value).write(value, subContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TableArrayValueWriter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "table-array";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,22 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Provides access to the keys and tables in a TOML data source.</p>
|
* <p>Provides access to the keys and tables in a TOML data source.</p>
|
||||||
@ -64,8 +73,9 @@ public class Toml
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return read(new InputStreamReader(new FileInputStream(file), "UTF8"));
|
return read(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -105,15 +115,18 @@ public class Toml
|
|||||||
line = bufferedReader.readLine();
|
line = bufferedReader.readLine();
|
||||||
}
|
}
|
||||||
read(w.toString());
|
read(w.toString());
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally
|
}
|
||||||
|
finally
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +168,7 @@ public class Toml
|
|||||||
|
|
||||||
public String getString(String key)
|
public String getString(String key)
|
||||||
{
|
{
|
||||||
return (String) get(key);
|
return (String)get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String key, String defaultValue)
|
public String getString(String key, String defaultValue)
|
||||||
@ -166,7 +179,7 @@ public class Toml
|
|||||||
|
|
||||||
public Long getLong(String key)
|
public Long getLong(String key)
|
||||||
{
|
{
|
||||||
return (Long) get(key);
|
return (Long)get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getLong(String key, Long defaultValue)
|
public Long getLong(String key, Long defaultValue)
|
||||||
@ -183,7 +196,7 @@ public class Toml
|
|||||||
public <T> List<T> getList(String key)
|
public <T> List<T> getList(String key)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<T> list = (List<T>) get(key);
|
List<T> list = (List<T>)get(key);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -203,7 +216,7 @@ public class Toml
|
|||||||
|
|
||||||
public Boolean getBoolean(String key)
|
public Boolean getBoolean(String key)
|
||||||
{
|
{
|
||||||
return (Boolean) get(key);
|
return (Boolean)get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getBoolean(String key, Boolean defaultValue)
|
public Boolean getBoolean(String key, Boolean defaultValue)
|
||||||
@ -214,7 +227,7 @@ public class Toml
|
|||||||
|
|
||||||
public Date getDate(String key)
|
public Date getDate(String key)
|
||||||
{
|
{
|
||||||
return (Date) get(key);
|
return (Date)get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDate(String key, Date defaultValue)
|
public Date getDate(String key, Date defaultValue)
|
||||||
@ -225,7 +238,7 @@ public class Toml
|
|||||||
|
|
||||||
public Double getDouble(String key)
|
public Double getDouble(String key)
|
||||||
{
|
{
|
||||||
return (Double) get(key);
|
return (Double)get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getDouble(String key, Double defaultValue)
|
public Double getDouble(String key, Double defaultValue)
|
||||||
@ -241,7 +254,7 @@ public class Toml
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Toml getTable(String key)
|
public Toml getTable(String key)
|
||||||
{
|
{
|
||||||
Map<String, Object> map = (Map<String, Object>) get(key);
|
Map<String, Object> map = (Map<String, Object>)get(key);
|
||||||
|
|
||||||
return map != null ? new Toml(null, map) : null;
|
return map != null ? new Toml(null, map) : null;
|
||||||
}
|
}
|
||||||
@ -253,7 +266,7 @@ public class Toml
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<Toml> getTables(String key)
|
public List<Toml> getTables(String key)
|
||||||
{
|
{
|
||||||
List<Map<String, Object>> tableArray = (List<Map<String, Object>>) get(key);
|
List<Map<String, Object>> tableArray = (List<Map<String, Object>>)get(key);
|
||||||
|
|
||||||
if (tableArray == null)
|
if (tableArray == null)
|
||||||
{
|
{
|
||||||
@ -386,17 +399,20 @@ public class Toml
|
|||||||
if (Map.class.isAssignableFrom(entryClass))
|
if (Map.class.isAssignableFrom(entryClass))
|
||||||
{
|
{
|
||||||
entries.add(new Entry(entry.getKey(), getTable(entry.getKey())));
|
entries.add(new Entry(entry.getKey(), getTable(entry.getKey())));
|
||||||
} else if (List.class.isAssignableFrom(entryClass))
|
}
|
||||||
|
else if (List.class.isAssignableFrom(entryClass))
|
||||||
{
|
{
|
||||||
List<?> value = (List<?>) entry.getValue();
|
List<?> value = (List<?>)entry.getValue();
|
||||||
if (!value.isEmpty() && value.get(0) instanceof Map)
|
if (!value.isEmpty() && value.get(0) instanceof Map)
|
||||||
{
|
{
|
||||||
entries.add(new Entry(entry.getKey(), getTables(entry.getKey())));
|
entries.add(new Entry(entry.getKey(), getTables(entry.getKey())));
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
entries.add(new Entry(entry.getKey(), value));
|
entries.add(new Entry(entry.getKey(), value));
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
entries.add(new Entry(entry.getKey(), entry.getValue()));
|
entries.add(new Entry(entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
@ -450,21 +466,21 @@ public class Toml
|
|||||||
|
|
||||||
for (dev.plex.toml.Keys.Key k : keys)
|
for (dev.plex.toml.Keys.Key k : keys)
|
||||||
{
|
{
|
||||||
if (k.index == -1 && current instanceof Map && ((Map<String, Object>) current).containsKey(k.path))
|
if (k.index == -1 && current instanceof Map && ((Map<String, Object>)current).containsKey(k.path))
|
||||||
{
|
{
|
||||||
return ((Map<String, Object>) current).get(k.path);
|
return ((Map<String, Object>)current).get(k.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = ((Map<String, Object>) current).get(k.name);
|
current = ((Map<String, Object>)current).get(k.name);
|
||||||
|
|
||||||
if (k.index > -1 && current != null)
|
if (k.index > -1 && current != null)
|
||||||
{
|
{
|
||||||
if (k.index >= ((List<?>) current).size())
|
if (k.index >= ((List<?>)current).size())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
current = ((List<?>) current).get(k.index);
|
current = ((List<?>)current).get(k.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current == null)
|
if (current == null)
|
||||||
|
@ -2,62 +2,87 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
class TomlParser {
|
class TomlParser
|
||||||
|
{
|
||||||
|
|
||||||
static dev.plex.toml.Results run(String tomlString) {
|
static dev.plex.toml.Results run(String tomlString)
|
||||||
final dev.plex.toml.Results results = new dev.plex.toml.Results();
|
{
|
||||||
|
final dev.plex.toml.Results results = new dev.plex.toml.Results();
|
||||||
if (tomlString.isEmpty()) {
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
AtomicInteger index = new AtomicInteger();
|
|
||||||
boolean inComment = false;
|
|
||||||
AtomicInteger line = new AtomicInteger(1);
|
|
||||||
dev.plex.toml.Identifier identifier = null;
|
|
||||||
Object value = null;
|
|
||||||
|
|
||||||
for (int i = index.get(); i < tomlString.length(); i = index.incrementAndGet()) {
|
|
||||||
char c = tomlString.charAt(i);
|
|
||||||
|
|
||||||
if (results.errors.hasErrors()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '#' && !inComment) {
|
if (tomlString.isEmpty())
|
||||||
inComment = true;
|
{
|
||||||
} else if (!Character.isWhitespace(c) && !inComment && identifier == null) {
|
return results;
|
||||||
dev.plex.toml.Identifier id = dev.plex.toml.IdentifierConverter.IDENTIFIER_CONVERTER.convert(tomlString, index, new dev.plex.toml.Context(null, line, results.errors));
|
|
||||||
|
|
||||||
if (id != dev.plex.toml.Identifier.INVALID) {
|
|
||||||
if (id.isKey()) {
|
|
||||||
identifier = id;
|
|
||||||
} else if (id.isTable()) {
|
|
||||||
results.startTables(id, line);
|
|
||||||
} else if (id.isTableArray()) {
|
|
||||||
results.startTableArray(id, line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (c == '\n') {
|
|
||||||
inComment = false;
|
AtomicInteger index = new AtomicInteger();
|
||||||
identifier = null;
|
boolean inComment = false;
|
||||||
value = null;
|
AtomicInteger line = new AtomicInteger(1);
|
||||||
line.incrementAndGet();
|
dev.plex.toml.Identifier identifier = null;
|
||||||
} else if (!inComment && identifier != null && identifier.isKey() && value == null && !Character.isWhitespace(c)) {
|
Object value = null;
|
||||||
value = ValueReaders.VALUE_READERS.convert(tomlString, index, new dev.plex.toml.Context(identifier, line, results.errors));
|
|
||||||
|
for (int i = index.get(); i < tomlString.length(); i = index.incrementAndGet())
|
||||||
if (value instanceof dev.plex.toml.Results.Errors) {
|
{
|
||||||
results.errors.add((dev.plex.toml.Results.Errors) value);
|
char c = tomlString.charAt(i);
|
||||||
} else {
|
|
||||||
results.addValue(identifier.getName(), value, line);
|
if (results.errors.hasErrors())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '#' && !inComment)
|
||||||
|
{
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
else if (!Character.isWhitespace(c) && !inComment && identifier == null)
|
||||||
|
{
|
||||||
|
dev.plex.toml.Identifier id = dev.plex.toml.IdentifierConverter.IDENTIFIER_CONVERTER.convert(tomlString, index, new dev.plex.toml.Context(null, line, results.errors));
|
||||||
|
|
||||||
|
if (id != dev.plex.toml.Identifier.INVALID)
|
||||||
|
{
|
||||||
|
if (id.isKey())
|
||||||
|
{
|
||||||
|
identifier = id;
|
||||||
|
}
|
||||||
|
else if (id.isTable())
|
||||||
|
{
|
||||||
|
results.startTables(id, line);
|
||||||
|
}
|
||||||
|
else if (id.isTableArray())
|
||||||
|
{
|
||||||
|
results.startTableArray(id, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '\n')
|
||||||
|
{
|
||||||
|
inComment = false;
|
||||||
|
identifier = null;
|
||||||
|
value = null;
|
||||||
|
line.incrementAndGet();
|
||||||
|
}
|
||||||
|
else if (!inComment && identifier != null && identifier.isKey() && value == null && !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
value = ValueReaders.VALUE_READERS.convert(tomlString, index, new dev.plex.toml.Context(identifier, line, results.errors));
|
||||||
|
|
||||||
|
if (value instanceof dev.plex.toml.Results.Errors)
|
||||||
|
{
|
||||||
|
results.errors.add((dev.plex.toml.Results.Errors)value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
results.addValue(identifier.getName(), value, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value != null && !inComment && !Character.isWhitespace(c))
|
||||||
|
{
|
||||||
|
results.errors.invalidTextAfterIdentifier(identifier, c, line.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (value != null && !inComment && !Character.isWhitespace(c)) {
|
|
||||||
results.errors.invalidTextAfterIdentifier(identifier, c, line.get());
|
return results;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
private TomlParser()
|
||||||
}
|
{
|
||||||
|
}
|
||||||
private TomlParser() {}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import static dev.plex.toml.ValueWriters.WRITERS;
|
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +117,8 @@ public class TomlWriter
|
|||||||
write(from, output, null);
|
write(from, output, null);
|
||||||
|
|
||||||
return output.toString();
|
return output.toString();
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -131,7 +137,8 @@ public class TomlWriter
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
write(from, outputStream, target);
|
write(from, outputStream, target);
|
||||||
} finally
|
}
|
||||||
|
finally
|
||||||
{
|
{
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
}
|
}
|
||||||
@ -146,7 +153,7 @@ public class TomlWriter
|
|||||||
*/
|
*/
|
||||||
public void write(Object from, OutputStream target, @Nullable File file) throws IOException
|
public void write(Object from, OutputStream target, @Nullable File file) throws IOException
|
||||||
{
|
{
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(target, "UTF-8");
|
OutputStreamWriter writer = new OutputStreamWriter(target, StandardCharsets.UTF_8);
|
||||||
write(from, writer, file);
|
write(from, writer, file);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
@ -170,7 +177,8 @@ public class TomlWriter
|
|||||||
context.file = file;
|
context.file = file;
|
||||||
}
|
}
|
||||||
valueWriter.write(from, context);
|
valueWriter.write(from, context);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("An object of class " + from.getClass().getSimpleName() + " cannot produce valid TOML. Please pass in a Map or a custom type.");
|
throw new IllegalArgumentException("An object of class " + from.getClass().getSimpleName() + " cannot produce valid TOML. Please pass in a Map or a custom type.");
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,20 @@ package dev.plex.toml;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
interface ValueReader {
|
interface ValueReader
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param s must already have been trimmed
|
* @param s must already have been trimmed
|
||||||
*/
|
*/
|
||||||
boolean canRead(String s);
|
boolean canRead(String s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partial validation. Stops after type terminator, rather than at EOI.
|
* Partial validation. Stops after type terminator, rather than at EOI.
|
||||||
*
|
*
|
||||||
* @param s must already have been validated by {@link #canRead(String)}
|
* @param s must already have been validated by {@link #canRead(String)}
|
||||||
* @param index where to start in s
|
* @param index where to start in s
|
||||||
* @return a value or a {@link dev.plex.toml.Results.Errors}
|
* @return a value or a {@link dev.plex.toml.Results.Errors}
|
||||||
*/
|
*/
|
||||||
Object read(String s, AtomicInteger index, dev.plex.toml.Context context);
|
Object read(String s, AtomicInteger index, dev.plex.toml.Context context);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static dev.plex.toml.ArrayValueReader.ARRAY_VALUE_READER;
|
import static dev.plex.toml.ArrayValueReader.ARRAY_VALUE_READER;
|
||||||
import static dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER;
|
import static dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER;
|
||||||
import static dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
import static dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
||||||
@ -10,26 +9,32 @@ import static dev.plex.toml.MultilineLiteralStringValueReader.MULTILINE_LITERAL_
|
|||||||
import static dev.plex.toml.MultilineStringValueReader.MULTILINE_STRING_VALUE_READER;
|
import static dev.plex.toml.MultilineStringValueReader.MULTILINE_STRING_VALUE_READER;
|
||||||
import static dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER;
|
import static dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER;
|
||||||
|
|
||||||
class ValueReaders {
|
class ValueReaders
|
||||||
|
{
|
||||||
static final ValueReaders VALUE_READERS = new ValueReaders();
|
|
||||||
|
static final ValueReaders VALUE_READERS = new ValueReaders();
|
||||||
Object convert(String value, AtomicInteger index, dev.plex.toml.Context context) {
|
|
||||||
String substring = value.substring(index.get());
|
Object convert(String value, AtomicInteger index, dev.plex.toml.Context context)
|
||||||
for (dev.plex.toml.ValueReader valueParser : READERS) {
|
{
|
||||||
if (valueParser.canRead(substring)) {
|
String substring = value.substring(index.get());
|
||||||
return valueParser.read(value, index, context);
|
for (dev.plex.toml.ValueReader valueParser : READERS)
|
||||||
}
|
{
|
||||||
|
if (valueParser.canRead(substring))
|
||||||
|
{
|
||||||
|
return valueParser.read(value, index, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||||
|
errors.invalidValue(context.identifier.getName(), substring, context.line.get());
|
||||||
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
private ValueReaders()
|
||||||
errors.invalidValue(context.identifier.getName(), substring, context.line.get());
|
{
|
||||||
return errors;
|
}
|
||||||
}
|
|
||||||
|
private static final dev.plex.toml.ValueReader[] READERS = {
|
||||||
private ValueReaders() {}
|
MULTILINE_STRING_VALUE_READER, MULTILINE_LITERAL_STRING_VALUE_READER, LITERAL_STRING_VALUE_READER, STRING_VALUE_READER_WRITER, DATE_VALUE_READER_WRITER, NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER, BOOLEAN_VALUE_READER_WRITER, ARRAY_VALUE_READER, InlineTableValueReader.INLINE_TABLE_VALUE_READER
|
||||||
|
};
|
||||||
private static final dev.plex.toml.ValueReader[] READERS = {
|
|
||||||
MULTILINE_STRING_VALUE_READER, MULTILINE_LITERAL_STRING_VALUE_READER, LITERAL_STRING_VALUE_READER, STRING_VALUE_READER_WRITER, DATE_VALUE_READER_WRITER, NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER, BOOLEAN_VALUE_READER_WRITER, ARRAY_VALUE_READER, InlineTableValueReader.INLINE_TABLE_VALUE_READER
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
interface ValueWriter {
|
interface ValueWriter
|
||||||
boolean canWrite(Object value);
|
{
|
||||||
|
boolean canWrite(Object value);
|
||||||
|
|
||||||
void write(Object value, WriterContext context);
|
void write(Object value, WriterContext context);
|
||||||
|
|
||||||
boolean isPrimitiveType();
|
boolean isPrimitiveType();
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,35 @@
|
|||||||
package dev.plex.toml;
|
package dev.plex.toml;
|
||||||
|
|
||||||
class ValueWriters {
|
class ValueWriters
|
||||||
|
{
|
||||||
|
|
||||||
static final ValueWriters WRITERS = new ValueWriters();
|
static final ValueWriters WRITERS = new ValueWriters();
|
||||||
|
|
||||||
ValueWriter findWriterFor(Object value) {
|
ValueWriter findWriterFor(Object value)
|
||||||
for (ValueWriter valueWriter : VALUE_WRITERS) {
|
{
|
||||||
if (valueWriter.canWrite(value)) {
|
for (ValueWriter valueWriter : VALUE_WRITERS)
|
||||||
return valueWriter;
|
{
|
||||||
}
|
if (valueWriter.canWrite(value))
|
||||||
|
{
|
||||||
|
return valueWriter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ObjectValueWriter.OBJECT_VALUE_WRITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ObjectValueWriter.OBJECT_VALUE_WRITER;
|
private ValueWriters()
|
||||||
}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private ValueWriters() {}
|
private static dev.plex.toml.DateValueReaderWriter getPlatformSpecificDateConverter()
|
||||||
|
{
|
||||||
private static dev.plex.toml.DateValueReaderWriter getPlatformSpecificDateConverter() {
|
String specificationVersion = Runtime.class.getPackage().getSpecificationVersion();
|
||||||
String specificationVersion = Runtime.class.getPackage().getSpecificationVersion();
|
return specificationVersion != null && specificationVersion.startsWith("1.6") ? dev.plex.toml.DateValueReaderWriter.DATE_PARSER_JDK_6 : dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
||||||
return specificationVersion != null && specificationVersion.startsWith("1.6") ? dev.plex.toml.DateValueReaderWriter.DATE_PARSER_JDK_6 : dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static final ValueWriter[] VALUE_WRITERS = {
|
private static final ValueWriter[] VALUE_WRITERS = {
|
||||||
StringValueReaderWriter.STRING_VALUE_READER_WRITER, NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER, dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER, getPlatformSpecificDateConverter(),
|
StringValueReaderWriter.STRING_VALUE_READER_WRITER, NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER, dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER, getPlatformSpecificDateConverter(),
|
||||||
MapValueWriter.MAP_VALUE_WRITER, dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER, TableArrayValueWriter.TABLE_ARRAY_VALUE_WRITER
|
MapValueWriter.MAP_VALUE_WRITER, dev.plex.toml.PrimitiveArrayValueWriter.PRIMITIVE_ARRAY_VALUE_WRITER, TableArrayValueWriter.TABLE_ARRAY_VALUE_WRITER
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,8 @@ class WriterContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -90,7 +91,8 @@ class WriterContext
|
|||||||
empty = false;
|
empty = false;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -113,7 +115,8 @@ class WriterContext
|
|||||||
if (isArrayOfTable)
|
if (isArrayOfTable)
|
||||||
{
|
{
|
||||||
write("[[").write(key).write("]]\n");
|
write("[[").write(key).write("]]\n");
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
write('[').write(key).write("]\n");
|
write('[').write(key).write("]\n");
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package dev.plex.util;
|
package dev.plex.util;
|
||||||
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
public class RandomUtil
|
public class RandomUtil
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,6 @@ package dev.plex.util;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -2,6 +2,7 @@ package dev.plex;
|
|||||||
|
|
||||||
import dev.plex.admin.Admin;
|
import dev.plex.admin.Admin;
|
||||||
import dev.plex.admin.AdminList;
|
import dev.plex.admin.AdminList;
|
||||||
|
import dev.plex.api.plugin.PlexPlugin;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.config.Config;
|
import dev.plex.config.Config;
|
||||||
@ -10,7 +11,6 @@ import dev.plex.handlers.ListenerHandler;
|
|||||||
import dev.plex.listener.impl.ChatListener;
|
import dev.plex.listener.impl.ChatListener;
|
||||||
import dev.plex.module.ModuleManager;
|
import dev.plex.module.ModuleManager;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.api.plugin.PlexPlugin;
|
|
||||||
import dev.plex.punishment.PunishmentManager;
|
import dev.plex.punishment.PunishmentManager;
|
||||||
import dev.plex.rank.RankManager;
|
import dev.plex.rank.RankManager;
|
||||||
import dev.plex.services.ServiceManager;
|
import dev.plex.services.ServiceManager;
|
||||||
@ -23,7 +23,11 @@ import dev.plex.storage.player.MongoPlayerData;
|
|||||||
import dev.plex.storage.player.SQLPlayerData;
|
import dev.plex.storage.player.SQLPlayerData;
|
||||||
import dev.plex.storage.punishment.SQLNotes;
|
import dev.plex.storage.punishment.SQLNotes;
|
||||||
import dev.plex.storage.punishment.SQLPunishment;
|
import dev.plex.storage.punishment.SQLPunishment;
|
||||||
import dev.plex.util.*;
|
import dev.plex.util.BuildInfo;
|
||||||
|
import dev.plex.util.BungeeUtil;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.UpdateChecker;
|
||||||
import dev.plex.world.CustomWorld;
|
import dev.plex.world.CustomWorld;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -3,7 +3,6 @@ package dev.plex.cache;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
getMap().register("plex", this);
|
getMap().register("plex", this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlexCommand()
|
public PlexCommand()
|
||||||
{
|
{
|
||||||
this(true);
|
this(true);
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.AdminAddEvent;
|
||||||
|
import dev.plex.api.event.AdminRemoveEvent;
|
||||||
|
import dev.plex.api.event.AdminSetRankEvent;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
@ -9,9 +12,6 @@ import dev.plex.command.annotation.System;
|
|||||||
import dev.plex.command.exception.ConsoleOnlyException;
|
import dev.plex.command.exception.ConsoleOnlyException;
|
||||||
import dev.plex.command.exception.PlayerNotFoundException;
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.api.event.AdminAddEvent;
|
|
||||||
import dev.plex.api.event.AdminRemoveEvent;
|
|
||||||
import dev.plex.api.event.AdminSetRankEvent;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.api.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.api.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -9,11 +9,10 @@ import dev.plex.punishment.Punishment;
|
|||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dev.plex.util.TimeUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.api.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -14,6 +14,9 @@ import dev.plex.util.BungeeUtil;
|
|||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.WebUtils;
|
import dev.plex.util.WebUtils;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -22,10 +25,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||||
public class KickCMD extends PlexCommand
|
public class KickCMD extends PlexCommand
|
||||||
|
@ -9,11 +9,10 @@ import dev.plex.punishment.Punishment;
|
|||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dev.plex.util.TimeUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -9,12 +9,11 @@ import dev.plex.punishment.Punishment;
|
|||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dev.plex.util.TimeUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.api.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.api.event.GameModeUpdateEvent;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.api.event.GameModeUpdateEvent;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.api.event.AdminAddEvent;
|
import dev.plex.api.event.AdminAddEvent;
|
||||||
import dev.plex.api.event.AdminRemoveEvent;
|
import dev.plex.api.event.AdminRemoveEvent;
|
||||||
import dev.plex.api.event.AdminSetRankEvent;
|
import dev.plex.api.event.AdminSetRankEvent;
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
@ -17,7 +17,7 @@ public class AdminListener extends PlexListener
|
|||||||
public void onAdminAdd(AdminAddEvent event)
|
public void onAdminAdd(AdminAddEvent event)
|
||||||
{
|
{
|
||||||
String userSender = event.getSender().getName();
|
String userSender = event.getSender().getName();
|
||||||
PlexPlayer target = (PlexPlayer) event.getPlexPlayer();
|
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
|
||||||
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
|
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||||
{
|
{
|
||||||
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
||||||
@ -35,7 +35,7 @@ public class AdminListener extends PlexListener
|
|||||||
public void onAdminRemove(AdminRemoveEvent event)
|
public void onAdminRemove(AdminRemoveEvent event)
|
||||||
{
|
{
|
||||||
String userSender = event.getSender().getName();
|
String userSender = event.getSender().getName();
|
||||||
PlexPlayer target = (PlexPlayer) event.getPlexPlayer();
|
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
|
||||||
target.setAdminActive(false);
|
target.setAdminActive(false);
|
||||||
DataUtils.update(target);
|
DataUtils.update(target);
|
||||||
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
|
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
|
||||||
@ -45,8 +45,8 @@ public class AdminListener extends PlexListener
|
|||||||
public void onAdminSetRank(AdminSetRankEvent event)
|
public void onAdminSetRank(AdminSetRankEvent event)
|
||||||
{
|
{
|
||||||
String userSender = event.getSender().getName();
|
String userSender = event.getSender().getName();
|
||||||
PlexPlayer target = (PlexPlayer) event.getPlexPlayer();
|
PlexPlayer target = (PlexPlayer)event.getPlexPlayer();
|
||||||
Rank newRank = (Rank) event.getRank();
|
Rank newRank = (Rank)event.getRank();
|
||||||
target.setRank(newRank.name().toLowerCase());
|
target.setRank(newRank.name().toLowerCase());
|
||||||
DataUtils.update(target);
|
DataUtils.update(target);
|
||||||
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
||||||
|
@ -5,7 +5,6 @@ import dev.plex.util.PlexUtils;
|
|||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.kyori.adventure.inventory.Book;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class ChatListener extends PlexListener
|
public class ChatListener extends PlexListener
|
||||||
{
|
{
|
||||||
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder().match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]").replacement((matchResult, builder) -> Component.empty().content(matchResult.group()).clickEvent(ClickEvent.openUrl(matchResult.group()))).build();
|
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder().match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]").replacement((matchResult, builder) -> Component.empty().content(matchResult.group()).clickEvent(ClickEvent.openUrl(matchResult.group()))).build();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChat(AsyncChatEvent event)
|
public void onChat(AsyncChatEvent event)
|
||||||
{
|
{
|
||||||
@ -34,6 +35,7 @@ public class ChatListener extends PlexListener
|
|||||||
public static class ChatHandlerImpl implements IChatHandler
|
public static class ChatHandlerImpl implements IChatHandler
|
||||||
{
|
{
|
||||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doChat(AsyncChatEvent event)
|
public void doChat(AsyncChatEvent event)
|
||||||
{
|
{
|
||||||
@ -44,7 +46,8 @@ public class ChatListener extends PlexListener
|
|||||||
{
|
{
|
||||||
renderer.hasPrefix = true;
|
renderer.hasPrefix = true;
|
||||||
renderer.prefix = prefix;
|
renderer.prefix = prefix;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
renderer.hasPrefix = false;
|
renderer.hasPrefix = false;
|
||||||
renderer.prefix = null;
|
renderer.prefix = null;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.api.event.AdminAddEvent;
|
import dev.plex.api.event.AdminAddEvent;
|
||||||
import dev.plex.api.event.AdminRemoveEvent;
|
import dev.plex.api.event.AdminRemoveEvent;
|
||||||
import dev.plex.api.event.AdminSetRankEvent;
|
import dev.plex.api.event.AdminSetRankEvent;
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -25,7 +25,7 @@ public class TabListener extends PlexListener
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onAdminAdd(AdminAddEvent event)
|
public void onAdminAdd(AdminAddEvent event)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = (PlexPlayer) event.getPlexPlayer();
|
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
|
||||||
Player player = event.getPlexPlayer().getPlayer();
|
Player player = event.getPlexPlayer().getPlayer();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ public class TabListener extends PlexListener
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onAdminRemove(AdminRemoveEvent event)
|
public void onAdminRemove(AdminRemoveEvent event)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = (PlexPlayer) event.getPlexPlayer();
|
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
|
||||||
Player player = event.getPlexPlayer().getPlayer();
|
Player player = event.getPlexPlayer().getPlayer();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
@ -49,7 +49,7 @@ public class TabListener extends PlexListener
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onAdminSetRank(AdminSetRankEvent event)
|
public void onAdminSetRank(AdminSetRankEvent event)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = (PlexPlayer) event.getPlexPlayer();
|
PlexPlayer plexPlayer = (PlexPlayer)event.getPlexPlayer();
|
||||||
Player player = event.getPlexPlayer().getPlayer();
|
Player player = event.getPlexPlayer().getPlayer();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ import org.bukkit.inventory.meta.SkullMeta;
|
|||||||
public class PunishmentMenu extends AbstractMenu
|
public class PunishmentMenu extends AbstractMenu
|
||||||
{
|
{
|
||||||
|
|
||||||
private List<Inventory> inventories = Lists.newArrayList();
|
private final List<Inventory> inventories = Lists.newArrayList();
|
||||||
|
|
||||||
public PunishmentMenu()
|
public PunishmentMenu()
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,6 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -124,7 +123,8 @@ public class ModuleManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Plex.get().getServer().getCommandMap().getCommand(plexCommand.getName()).unregister(Plex.get().getServer().getCommandMap());
|
Plex.get().getServer().getCommandMap().getCommand(plexCommand.getName()).unregister(Plex.get().getServer().getCommandMap());
|
||||||
} catch (Exception ignored)
|
}
|
||||||
|
catch (Exception ignored)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ import dev.plex.punishment.extra.Note;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -23,11 +27,6 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity(value = "players", useDiscriminator = false)
|
@Entity(value = "players", useDiscriminator = false)
|
||||||
@ -119,11 +118,13 @@ public class PlexPlayer implements IPlexPlayer
|
|||||||
if (player.isOp())
|
if (player.isOp())
|
||||||
{
|
{
|
||||||
return Rank.OP;
|
return Rank.OP;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return Rank.NONOP;
|
return Rank.NONOP;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return Rank.valueOf(rank.toUpperCase());
|
return Rank.valueOf(rank.toUpperCase());
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,10 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.util.MojangUtils;
|
import dev.plex.util.MojangUtils;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
||||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
@ -10,6 +10,7 @@ import dev.plex.player.PlexPlayer;
|
|||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -21,8 +22,6 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import dev.plex.util.TimeUtils;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
@ -2,10 +2,9 @@ package dev.plex.punishment.extra;
|
|||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
|
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -30,7 +30,7 @@ public enum Rank implements IRank
|
|||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private NamedTextColor color;
|
private final NamedTextColor color;
|
||||||
|
|
||||||
Rank(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
Rank(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ public enum Title
|
|||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private NamedTextColor color;
|
private final NamedTextColor color;
|
||||||
|
|
||||||
Title(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
Title(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
||||||
{
|
{
|
||||||
|
@ -7,8 +7,8 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
public abstract class AbstractService implements IService, PlexBase
|
public abstract class AbstractService implements IService, PlexBase
|
||||||
{
|
{
|
||||||
private boolean asynchronous;
|
private final boolean asynchronous;
|
||||||
private boolean repeating;
|
private final boolean repeating;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private int taskId;
|
private int taskId;
|
||||||
|
@ -7,7 +7,6 @@ import dev.plex.cache.PlayerCache;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -38,7 +37,8 @@ public class SQLPlayerData
|
|||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
return set.next();
|
return set.next();
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -53,7 +53,8 @@ public class SQLPlayerData
|
|||||||
statement.setString(1, username);
|
statement.setString(1, username);
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
return set.next();
|
return set.next();
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -104,7 +105,8 @@ public class SQLPlayerData
|
|||||||
plexPlayer.setCommandSpy(commandspy);
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
}
|
}
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -153,7 +155,8 @@ public class SQLPlayerData
|
|||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -216,11 +219,13 @@ public class SQLPlayerData
|
|||||||
plexPlayer.setCommandSpy(commandspy);
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
}
|
}
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
}
|
||||||
|
else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||||
{
|
{
|
||||||
PlexLog.warn("Querying a user by IP running SQLite can cause performance issues! Please try to switch to a remote DB ASAP!");
|
PlexLog.warn("Querying a user by IP running SQLite can cause performance issues! Please try to switch to a remote DB ASAP!");
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
@ -260,7 +265,8 @@ public class SQLPlayerData
|
|||||||
plexPlayer.setCommandSpy(commandspy);
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
}
|
}
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -290,7 +296,8 @@ public class SQLPlayerData
|
|||||||
statement.setBoolean(9, player.isCommandSpy());
|
statement.setBoolean(9, player.isCommandSpy());
|
||||||
statement.setString(10, player.getUuid().toString());
|
statement.setString(10, player.getUuid().toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -318,7 +325,8 @@ public class SQLPlayerData
|
|||||||
statement.setBoolean(9, player.isVanished());
|
statement.setBoolean(9, player.isVanished());
|
||||||
statement.setBoolean(10, player.isCommandSpy());
|
statement.setBoolean(10, player.isCommandSpy());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException throwables)
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@ import com.google.common.collect.Lists;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.punishment.extra.Note;
|
import dev.plex.punishment.extra.Note;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.*;
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
@ -6,7 +6,6 @@ import dev.plex.punishment.Punishment;
|
|||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -47,7 +46,8 @@ public class SQLPunishment
|
|||||||
punishment.setIp(set.getString("ip"));
|
punishment.setIp(set.getString("ip"));
|
||||||
punishments.add(punishment);
|
punishments.add(punishment);
|
||||||
}
|
}
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return punishments;
|
return punishments;
|
||||||
@ -76,7 +76,8 @@ public class SQLPunishment
|
|||||||
punishment.setIp(set.getString("ip"));
|
punishment.setIp(set.getString("ip"));
|
||||||
punishments.add(punishment);
|
punishments.add(punishment);
|
||||||
}
|
}
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -103,7 +104,8 @@ public class SQLPunishment
|
|||||||
statement.setLong(9, punishment.getEndDate().toInstant().toEpochMilli());
|
statement.setLong(9, punishment.getEndDate().toInstant().toEpochMilli());
|
||||||
PlexLog.debug("Executing punishment");
|
PlexLog.debug("Executing punishment");
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -126,7 +128,8 @@ public class SQLPunishment
|
|||||||
statement1.setString(3, uuid.toString());
|
statement1.setString(3, uuid.toString());
|
||||||
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
||||||
statement1.executeUpdate();
|
statement1.executeUpdate();
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -151,7 +154,8 @@ public class SQLPunishment
|
|||||||
statement1.setString(3, uuid.toString());
|
statement1.setString(3, uuid.toString());
|
||||||
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
statement1.setString(4, PunishmentType.TEMPBAN.name());
|
||||||
statement1.executeUpdate();
|
statement1.executeUpdate();
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package dev.plex.util;
|
package dev.plex.util;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -2,6 +2,7 @@ package dev.plex.util;
|
|||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import dev.plex.Plex;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -9,8 +10,6 @@ import java.time.ZoneId;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
@ -4,6 +4,14 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.Month;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
@ -17,15 +25,6 @@ import org.bukkit.command.PluginCommandYamlParser;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.Month;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PlexUtils implements PlexBase
|
public class PlexUtils implements PlexBase
|
||||||
{
|
{
|
||||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||||
@ -71,18 +70,21 @@ public class PlexUtils implements PlexBase
|
|||||||
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
||||||
{
|
{
|
||||||
PlexLog.log("Successfully enabled MySQL!");
|
PlexLog.log("Successfully enabled MySQL!");
|
||||||
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
}
|
||||||
|
else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||||
{
|
{
|
||||||
PlexLog.log("Successfully enabled SQLite!");
|
PlexLog.log("Successfully enabled SQLite!");
|
||||||
}
|
}
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
if (Plex.get().getMongoConnection().getDatastore() != null)
|
if (Plex.get().getMongoConnection().getDatastore() != null)
|
||||||
{
|
{
|
||||||
PlexLog.log("Successfully enabled MongoDB!");
|
PlexLog.log("Successfully enabled MongoDB!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (Plex.get().getMongoConnection().getDatastore() != null)
|
if (Plex.get().getMongoConnection().getDatastore() != null)
|
||||||
{
|
{
|
||||||
@ -172,8 +174,9 @@ public class PlexUtils implements PlexBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return ((TextComponent) component).content();
|
return ((TextComponent)component).content();
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PlexLog.warn("Unable to get text of component", e.getLocalizedMessage());
|
PlexLog.warn("Unable to get text of component", e.getLocalizedMessage());
|
||||||
return "";
|
return "";
|
||||||
@ -192,7 +195,8 @@ public class PlexUtils implements PlexBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PlexLog.warn("Unable to get text of components", e.getLocalizedMessage());
|
PlexLog.warn("Unable to get text of components", e.getLocalizedMessage());
|
||||||
return "";
|
return "";
|
||||||
|
@ -5,7 +5,6 @@ import com.google.gson.JsonDeserializer;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
@ -13,7 +12,8 @@ import java.time.ZonedDateTime;
|
|||||||
|
|
||||||
public class ZonedDateTimeDeserializer implements JsonDeserializer<ZonedDateTime>
|
public class ZonedDateTimeDeserializer implements JsonDeserializer<ZonedDateTime>
|
||||||
{
|
{
|
||||||
private static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
private static final String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
{
|
{
|
||||||
|
@ -5,13 +5,13 @@ import com.google.gson.JsonPrimitive;
|
|||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
import com.google.gson.JsonSerializer;
|
import com.google.gson.JsonSerializer;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
public class ZonedDateTimeSerializer implements JsonSerializer<ZonedDateTime>
|
public class ZonedDateTimeSerializer implements JsonSerializer<ZonedDateTime>
|
||||||
{
|
{
|
||||||
private static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
private static final String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public abstract class AbstractMenu implements Listener
|
public abstract class AbstractMenu implements Listener
|
||||||
{
|
{
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
public AbstractMenu(String name)
|
public AbstractMenu(String name)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dev.plex.util.minimessage;
|
package dev.plex.util.minimessage;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import java.util.List;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.Context;
|
import net.kyori.adventure.text.minimessage.Context;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
@ -11,8 +12,6 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SafeMiniMessage
|
public class SafeMiniMessage
|
||||||
{
|
{
|
||||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(new SafeMiniMessageTagResolver()).build();
|
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(new SafeMiniMessageTagResolver()).build();
|
||||||
|
Loading…
Reference in New Issue
Block a user