....
This commit is contained in:
@ -1,119 +0,0 @@
|
||||
package io.github.p2vman.config;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class MiniConfig {
|
||||
|
||||
public static JsonObject parse(String input) {
|
||||
return parseBlock(new Scanner(input));
|
||||
}
|
||||
|
||||
private static JsonObject parseBlock(Scanner scanner) {
|
||||
JsonObject obj = new JsonObject();
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
if (line.isEmpty() || line.startsWith("#") || line.startsWith("//")) continue;
|
||||
|
||||
if (line.endsWith("{")) {
|
||||
String key = line.substring(0, line.length() - 1).trim();
|
||||
JsonObject nested = parseBlock(scanner);
|
||||
obj.add(key, nested);
|
||||
} else if (line.equals("}")) {
|
||||
break;
|
||||
} else if (line.endsWith("[")) {
|
||||
String key = line.substring(0, line.length() - 1).trim();
|
||||
JsonArray array = parseArrayBlock(scanner);
|
||||
obj.add(key, array);
|
||||
} else {
|
||||
String[] parts = line.split("=", 2);
|
||||
if (parts.length != 2) continue;
|
||||
String key = parts[0].trim();
|
||||
String value = parts[1].trim();
|
||||
obj.add(key, parseValue(value));
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static JsonArray parseArrayBlock(Scanner scanner) {
|
||||
JsonArray array = new JsonArray();
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
if (line.equals("]")) break;
|
||||
if (line.equals("{")) {
|
||||
array.add(parseBlock(scanner));
|
||||
} else {
|
||||
array.add(parseValue(line));
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static JsonElement parseValue(String value) {
|
||||
if (value.equals("true") || value.equals("false")) return new JsonPrimitive(Boolean.parseBoolean(value));
|
||||
try { return new JsonPrimitive(Integer.parseInt(value)); } catch (NumberFormatException ignored) {}
|
||||
try { return new JsonPrimitive(Double.parseDouble(value)); } catch (NumberFormatException ignored) {}
|
||||
if (value.startsWith("\"") && value.endsWith("\"")) return new JsonPrimitive(value.substring(1, value.length() - 1));
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
|
||||
public static String toMiniConf(JsonObject obj, int indent) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
writeObject(sb, obj, indent);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void writeObject(StringBuilder sb, JsonObject obj, int indent) {
|
||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
String pad = indent(indent);
|
||||
String key = entry.getKey();
|
||||
JsonElement val = entry.getValue();
|
||||
|
||||
if (val.isJsonObject()) {
|
||||
sb.append(pad).append(key).append(" {\n");
|
||||
writeObject(sb, val.getAsJsonObject(), indent + 2);
|
||||
sb.append(pad).append("}\n");
|
||||
} else if (val.isJsonArray()) {
|
||||
sb.append(pad).append(key).append(" [\n");
|
||||
writeArray(sb, val.getAsJsonArray(), indent + 2);
|
||||
sb.append(pad).append("]\n");
|
||||
} else {
|
||||
sb.append(pad).append(key).append(" = ").append(formatValue(val)).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeArray(StringBuilder sb, JsonArray array, int indent) {
|
||||
for (JsonElement el : array) {
|
||||
String pad = indent(indent);
|
||||
if (el.isJsonObject()) {
|
||||
sb.append(pad).append("{\n");
|
||||
writeObject(sb, el.getAsJsonObject(), indent + 2);
|
||||
sb.append(pad).append("}\n");
|
||||
} else {
|
||||
sb.append(pad).append(formatValue(el)).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatValue(JsonElement val) {
|
||||
if (val.isJsonPrimitive()) {
|
||||
JsonPrimitive prim = val.getAsJsonPrimitive();
|
||||
if (prim.isString()) return "\"" + prim.getAsString() + "\"";
|
||||
return prim.toString();
|
||||
}
|
||||
return val.toString();
|
||||
}
|
||||
|
||||
private static String indent(int count) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < count; i++) sb.append(' ');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
package io.github.p2vman.eptalist;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.github.p2vman.Identifier;
|
||||
import io.github.p2vman.Static;
|
||||
import io.github.p2vman.Utils;
|
||||
import io.github.p2vman.config.MiniConfig;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
@ -58,10 +55,8 @@ public class Config {
|
||||
public static class ConfigContainer {
|
||||
private File config;
|
||||
private Config cfg = null;
|
||||
private boolean json;
|
||||
public ConfigContainer(File config) {
|
||||
this.config = config;
|
||||
this.json = config.getName().endsWith(".json");
|
||||
}
|
||||
|
||||
public Config get() {
|
||||
@ -77,16 +72,7 @@ public class Config {
|
||||
save();
|
||||
} else {
|
||||
try (Reader reader = new InputStreamReader(new FileInputStream(config), "UTF-8")) {
|
||||
if (json) {
|
||||
cfg = Static.GSON.fromJson(reader, Config.class);
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
BufferedReader br = new BufferedReader(reader);
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) sb.append(line).append('\n');
|
||||
JsonObject raw = MiniConfig.parse(sb.toString());
|
||||
cfg = Static.GSON.fromJson(raw, Config.class);
|
||||
}
|
||||
cfg = Static.GSON.fromJson(reader, Config.class);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -96,12 +82,7 @@ public class Config {
|
||||
|
||||
public void save() {
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(config), "UTF-8")) {
|
||||
if (json) {
|
||||
Static.GSON.toJson(cfg, writer);
|
||||
} else {
|
||||
JsonElement tree = Static.GSON.toJsonTree(cfg);
|
||||
writer.write(MiniConfig.toMiniConf(tree.getAsJsonObject(), 0));
|
||||
}
|
||||
Static.GSON.toJson(cfg, writer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
version = 1.8
|
||||
version = 1.8.0000a
|
8
gradlew
vendored
8
gradlew
vendored
@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@ -203,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
@ -75,7 +75,7 @@ public final class EptaList extends JavaPlugin {
|
||||
data.mkdirs();
|
||||
}
|
||||
|
||||
config = new Config.ConfigContainer(new File(data, "config.cfg"));
|
||||
config = new Config.ConfigContainer(new File(data, "config.json"));
|
||||
load();
|
||||
|
||||
if (config.get().auto_update_check) {
|
||||
|
@ -19,7 +19,11 @@ public class Event implements Listener {
|
||||
if (config.enable) {
|
||||
if (!(config.skip_to_op && p.isOp())) {
|
||||
EptaList.list.isAsync(p.getName(), p::sendMessage).thenAccept((ea) -> {
|
||||
if (!ea) p.kickPlayer(ChatColor.translateAlternateColorCodes('&', EptaList.mode.kick_msg));
|
||||
if (!ea) try {
|
||||
p.kickPlayer(ChatColor.translateAlternateColorCodes('&', EptaList.mode.kick_msg));
|
||||
} catch (Exception exception) {
|
||||
p.kickPlayer(Lang.LANG.format("err.internal"));
|
||||
}
|
||||
}).exceptionally(er -> {
|
||||
p.kickPlayer(Lang.LANG.format("err.internal"));
|
||||
return null;
|
||||
|
@ -39,7 +39,6 @@ public class Velocity {
|
||||
@Inject
|
||||
private Logger logger;
|
||||
public static Config.ConfigContainer config;
|
||||
private Path dataDirectory;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
|
||||
public static Data<String> list;
|
||||
@ -71,7 +70,6 @@ public class Velocity {
|
||||
public Velocity(ProxyServer server, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
|
||||
profiler.push("init");
|
||||
this.metricsFactory = metricsFactory;
|
||||
this.dataDirectory = dataDirectory;
|
||||
if (!Files.exists(dataDirectory)) {
|
||||
dataDirectory.toFile().mkdirs();
|
||||
}
|
||||
@ -108,7 +106,7 @@ public class Velocity {
|
||||
|
||||
@Subscribe
|
||||
public void onLogin(LoginEvent event) {
|
||||
if (list.is(event.getPlayer().getUsername())) {
|
||||
if (!list.is(event.getPlayer().getUsername())) {
|
||||
event.setResult(ResultedEvent.ComponentResult.denied(Component.text(mode.kick_msg)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user