upd
This commit is contained in:
parent
1cdd60934d
commit
f3fcfdefdd
BIN
ModuleLoader.zip
BIN
ModuleLoader.zip
Binary file not shown.
|
@ -17,7 +17,7 @@ dependencies {
|
|||
compileOnly "com.google.code.gson:gson:2.8.9"
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.30'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.30'
|
||||
compileOnly("com.moandjiezana.toml:toml4j:0.7.2")
|
||||
//implementation 'com.ibm.async:asyncutil:0.1.0'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
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,16 +1,14 @@
|
|||
package io.github.p2vman.eptalist;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.moandjiezana.toml.Toml;
|
||||
import com.moandjiezana.toml.TomlWriter;
|
||||
import io.github.p2vman.Identifier;
|
||||
import io.github.p2vman.Static;
|
||||
import io.github.p2vman.Utils;
|
||||
import io.github.p2vman.config.MiniConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -72,26 +70,22 @@ public class Config {
|
|||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
if (!config.exists()) {
|
||||
this.cfg = new Config();
|
||||
try (FileWriter writer =new FileWriter(this.config, StandardCharsets.UTF_8)) {
|
||||
if (json) {
|
||||
Static.GSON.toJson(cfg, writer);
|
||||
}
|
||||
else {
|
||||
new TomlWriter().write(cfg, writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try (FileReader reader = new FileReader(this.config, StandardCharsets.UTF_8)) {
|
||||
save();
|
||||
} else {
|
||||
try (Reader reader = new InputStreamReader(new FileInputStream(config), "UTF-8")) {
|
||||
if (json) {
|
||||
cfg = Static.GSON.fromJson(reader, Config.class);
|
||||
} else {
|
||||
cfg = new Toml().read(reader).to(Config.class);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,12 +95,12 @@ public class Config {
|
|||
}
|
||||
|
||||
public void save() {
|
||||
try (FileWriter writer = new FileWriter(this.config, StandardCharsets.UTF_8)) {
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(config), "UTF-8")) {
|
||||
if (json) {
|
||||
Static.GSON.toJson(cfg, writer);
|
||||
}
|
||||
else {
|
||||
new TomlWriter().write(cfg, writer);
|
||||
} else {
|
||||
JsonElement tree = Static.GSON.toJsonTree(cfg);
|
||||
writer.write(MiniConfig.toMiniConf(tree.getAsJsonObject(), 0));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,17 +1,45 @@
|
|||
package io.github.p2vman.eptalist.storge;
|
||||
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface Data<T> extends Closeable {
|
||||
boolean addUser(T name);
|
||||
boolean removeUser(T name);
|
||||
boolean is(T name);
|
||||
List<T> toList();
|
||||
boolean addUser(T name, List<String> info);
|
||||
boolean removeUser(T name, List<String> info);
|
||||
boolean is(T name, List<String> info);
|
||||
boolean addUser(T name, Consumer<String> callback);
|
||||
boolean removeUser(T name, Consumer<String> callback);
|
||||
boolean is(T name, Consumer<String> callback);
|
||||
default boolean dirty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default CompletionStage<Boolean> addUserAsync(T name, Consumer<String> callback) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
synchronized (this) {
|
||||
return addUser(name, callback);
|
||||
}
|
||||
}, Storge.threadPool);
|
||||
}
|
||||
|
||||
default CompletableFuture<Boolean> removeUserAsync(T name, Consumer<String> callback) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
synchronized (this) {
|
||||
return removeUser(name, callback);
|
||||
}
|
||||
}, Storge.threadPool);
|
||||
}
|
||||
|
||||
default CompletableFuture<Boolean> isAsync(T name, Consumer<String> callback) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
synchronized (this) {
|
||||
return is(name, callback);
|
||||
}
|
||||
}, Storge.threadPool);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import io.github.p2vman.lang.Lang;
|
|||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Json extends ArrayList<String> implements Data<String> {
|
||||
@Override
|
||||
|
@ -104,23 +105,23 @@ public class Json extends ArrayList<String> implements Data<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean is(String name, List<String> info) {
|
||||
public boolean is(String name, Consumer<String> info) {
|
||||
return contains(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeUser(String name, List<String> info) {
|
||||
public boolean removeUser(String name, Consumer<String> info) {
|
||||
if (!is(name)) {
|
||||
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||
info.accept(Lang.LANG.format("storge.remove.not.in", name));
|
||||
return false;
|
||||
}
|
||||
return remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addUser(String name, List<String> info) {
|
||||
public boolean addUser(String name, Consumer<String> info) {
|
||||
if (is(name)) {
|
||||
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||
info.accept(Lang.LANG.format("storge.add.is.already", name));
|
||||
return false;
|
||||
}
|
||||
return add(name);
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.sql.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Mysql implements Data<String> {
|
||||
public Connection connection;
|
||||
|
@ -44,9 +45,9 @@ public class Mysql implements Data<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeUser(String name, List<String> info) {
|
||||
public boolean removeUser(String name, Consumer<String> info) {
|
||||
if (!is(name)) {
|
||||
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||
info.accept(Lang.LANG.format("storge.remove.not.in", name));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -55,17 +56,17 @@ public class Mysql implements Data<String> {
|
|||
return statement.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
info.add(Lang.LANG.format("err.db"));
|
||||
info.accept(Lang.LANG.format("err.db"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(String name, List<String> info) {
|
||||
public boolean is(String name, Consumer<String> info) {
|
||||
try {
|
||||
if (connection.isClosed()) {
|
||||
connection = DriverManager.getConnection(String.format((String) this.data.get("file")));
|
||||
info.add(Lang.LANG.format("storge.reconnect"));
|
||||
info.accept(Lang.LANG.format("storge.reconnect"));
|
||||
}
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT user_name FROM "+this.teable+" WHERE "+this.i+" = ?");
|
||||
statement.setString(1, name);
|
||||
|
@ -73,7 +74,7 @@ public class Mysql implements Data<String> {
|
|||
return resultSet.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
info.add(Lang.LANG.format("err.db"));
|
||||
info.accept(Lang.LANG.format("err.db"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -95,9 +96,9 @@ public class Mysql implements Data<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean addUser(String name, List<String> info) {
|
||||
public boolean addUser(String name, Consumer<String> info) {
|
||||
if (is(name)) {
|
||||
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||
info.accept(Lang.LANG.format("storge.add.is.already", name));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -106,7 +107,7 @@ public class Mysql implements Data<String> {
|
|||
return statement.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
info.add(Lang.LANG.format("err.db"));
|
||||
info.accept(Lang.LANG.format("err.db"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.github.p2vman.utils.Pair;
|
|||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
|
@ -139,23 +140,23 @@ public class NBT extends ArrayList<String> implements Data<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean is(String name, List<String> info) {
|
||||
public boolean is(String name, Consumer<String> info) {
|
||||
return contains(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeUser(String name, List<String> info) {
|
||||
public boolean removeUser(String name, Consumer<String> info) {
|
||||
if (!is(name)) {
|
||||
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||
info.accept(Lang.LANG.format("storge.remove.not.in", name));
|
||||
return false;
|
||||
}
|
||||
return remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addUser(String name, List<String> info) {
|
||||
public boolean addUser(String name, Consumer<String> info) {
|
||||
if (is(name)) {
|
||||
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||
info.accept(Lang.LANG.format("storge.add.is.already", name));
|
||||
return false;
|
||||
}
|
||||
return add(name);
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.sql.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Sqlite implements Data<String> {
|
||||
|
||||
|
@ -45,9 +46,9 @@ public class Sqlite implements Data<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean removeUser(String name, List<String> info) {
|
||||
public boolean removeUser(String name, Consumer<String> info) {
|
||||
if (!is(name)) {
|
||||
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||
info.accept(Lang.LANG.format("storge.remove.not.in", name));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -56,17 +57,17 @@ public class Sqlite implements Data<String> {
|
|||
return statement.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
info.add(Lang.LANG.format("err.db"));
|
||||
info.accept(Lang.LANG.format("err.db"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(String name, List<String> info) {
|
||||
public boolean is(String name, Consumer<String> info) {
|
||||
try {
|
||||
if (connection.isClosed()) {
|
||||
connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s.db", (String) this.data.get("file")));
|
||||
info.add(Lang.LANG.format("storge.reconnect"));
|
||||
info.accept(Lang.LANG.format("storge.reconnect"));
|
||||
}
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT "+this.i+" FROM "+this.teable+" WHERE "+this.i+" = ?");
|
||||
statement.setString(1, name);
|
||||
|
@ -74,7 +75,7 @@ public class Sqlite implements Data<String> {
|
|||
return resultSet.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
info.add(Lang.LANG.format("err.db"));
|
||||
info.accept(Lang.LANG.format("err.db"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -96,9 +97,9 @@ public class Sqlite implements Data<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean addUser(String name, List<String> info) {
|
||||
public boolean addUser(String name, Consumer<String> info) {
|
||||
if (is(name)) {
|
||||
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||
info.accept(Lang.LANG.format("storge.add.is.already", name));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -107,7 +108,7 @@ public class Sqlite implements Data<String> {
|
|||
return statement.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
info.add(Lang.LANG.format("err.db"));
|
||||
info.accept(Lang.LANG.format("err.db"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,35 +8,53 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
@ApiStatus.In_Development
|
||||
public abstract class Storge<T> implements Closeable {
|
||||
public static ExecutorService threadPool = Executors.newFixedThreadPool(2, new ThreadFactory() {
|
||||
private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
|
||||
private int count = 0;
|
||||
|
||||
public static final Map<String, Class<? extends Data<String>>> sm = Utils.wappeler(new HashMap<String, Class<? extends Data<String>>>())
|
||||
.put("NBT", NBT.class)
|
||||
.put("nbt", NBT.class)
|
||||
.put("JSON", Json.class)
|
||||
.put("json", Json.class)
|
||||
.put("Sqlite", Sqlite.class)
|
||||
.put("SQLITE", Sqlite.class)
|
||||
.put("mysql", Mysql.class)
|
||||
.put("MYSQL", Mysql.class)
|
||||
.put("org.eptalist.storge.Json", Json.class)
|
||||
.put("org.eptalist.storge.NBT", NBT.class)
|
||||
.put("org.eptalist.storge.Sqlite", Sqlite.class)
|
||||
.put("org.eptalist.storge.Mysql", Mysql.class)
|
||||
.getMap();
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = defaultFactory.newThread(r);
|
||||
t.setName("data-async-pool-" + count++);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
}
|
||||
});
|
||||
|
||||
public static final Map<String, Class<? extends Data<String>>> sm;
|
||||
|
||||
static {
|
||||
sm = new HashMap<>();
|
||||
sm.put("NBT", NBT.class);
|
||||
sm.put("nbt", NBT.class);
|
||||
sm.put("JSON", Json.class);
|
||||
sm.put("json", Json.class);
|
||||
sm.put("Sqlite", Sqlite.class);
|
||||
sm.put("SQLITE", Sqlite.class);
|
||||
sm.put("mysql", Mysql.class);
|
||||
sm.put("MYSQL", Mysql.class);
|
||||
sm.put("org.eptalist.storge.Json", Json.class);
|
||||
sm.put("org.eptalist.storge.NBT", NBT.class);
|
||||
sm.put("org.eptalist.storge.Sqlite", Sqlite.class);
|
||||
sm.put("org.eptalist.storge.Mysql", Mysql.class);
|
||||
}
|
||||
|
||||
public static Class<? extends Data<String>> find(String clz) throws ClassNotFoundException, ClassCastException {
|
||||
Class<?> cls = null;
|
||||
if (sm.containsKey(clz)) {
|
||||
cls = sm.get(clz);
|
||||
}
|
||||
|
||||
try {
|
||||
cls = Class.forName(clz);
|
||||
} catch (Exception e) {
|
||||
} else {
|
||||
try {
|
||||
cls = Class.forName(clz);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (cls == null) throw new ClassNotFoundException();
|
||||
|
@ -54,12 +72,14 @@ public abstract class Storge<T> implements Closeable {
|
|||
}
|
||||
|
||||
public abstract List<T> toList();
|
||||
public abstract Answer addUserAsync(T name);
|
||||
public abstract Answer addUser(T name);
|
||||
public abstract Answer removeUser(T name);
|
||||
public abstract Answer is(T name);
|
||||
public abstract Answer removeUserAsync(T name);
|
||||
public abstract Answer isAsync(T name);
|
||||
|
||||
@ApiStatus.In_Development
|
||||
public class Answer {
|
||||
public static class Answer {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
"reconnect": "&6The database has been reconnected"
|
||||
},
|
||||
"err": {
|
||||
"db": "&4There was an error in the database"
|
||||
"db": "&4There was an error in the database",
|
||||
"internal": "&4 internal server error"
|
||||
},
|
||||
"command": {
|
||||
"reload": {
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
"reconnect": "&6Подключение к базе данных восстановлено"
|
||||
},
|
||||
"err": {
|
||||
"db": "&4Произошла ошибка в базе данных"
|
||||
"db": "&4Произошла ошибка в базе данных",
|
||||
"internal": "&4 internal server error"
|
||||
},
|
||||
"command": {
|
||||
"reload": {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"p2vman"
|
||||
],
|
||||
"urls": {
|
||||
"source": "https://github.com/p2vman/EptaListProject",
|
||||
"source": "https://git.eptaproject.space/p2vman/EptaListProject",
|
||||
"discord": "https://discord.gg/UdSXf4tpUF"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,11 +49,8 @@ public class WhiteListCommand extends Command implements TabExecutor {
|
|||
break;
|
||||
}
|
||||
String usernameToAdd = args[1];
|
||||
List<String> infoAdd = new ArrayList<>();
|
||||
if (Boungecord.list.addUser(usernameToAdd, infoAdd)) {
|
||||
if (Boungecord.list.addUser(usernameToAdd, (t) -> sender.sendMessage(new TextComponent((String) t)))) {
|
||||
sender.sendMessage(new TextComponent(Lang.LANG.format("command.add.succes", usernameToAdd)));
|
||||
} else {
|
||||
infoAdd.forEach(line -> sender.sendMessage(new TextComponent(line)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -63,11 +60,8 @@ public class WhiteListCommand extends Command implements TabExecutor {
|
|||
break;
|
||||
}
|
||||
String usernameToRemove = args[1];
|
||||
List<String> infoRemove = new ArrayList<>();
|
||||
if (Boungecord.list.removeUser(usernameToRemove, infoRemove)) {
|
||||
if (Boungecord.list.removeUser(usernameToRemove, (t) -> sender.sendMessage(new TextComponent((String) t)))) {
|
||||
sender.sendMessage(new TextComponent(Lang.LANG.format("command.remove.succes", usernameToRemove)));
|
||||
} else {
|
||||
infoRemove.forEach(line -> sender.sendMessage(new TextComponent(line)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ tasks.build {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.moandjiezana.toml:toml4j:0.7.2")
|
||||
//implementation 'com.ibm.async:asyncutil:0.1.0'
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
|
|
|
@ -1 +1 @@
|
|||
version = 1.6
|
||||
version = 1.8
|
|
@ -32,7 +32,7 @@ public final class EptaList extends JavaPlugin {
|
|||
public static final Logger LOGGER = Logger.getLogger("EptaList");
|
||||
|
||||
public static Config.ConfigContainer config;
|
||||
public static Data list;
|
||||
public static Data<String> list;
|
||||
public static Config.Mode mode;
|
||||
public static List<Identifier> identifiers = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.p2vman.eptalist.spigot;
|
||||
|
||||
import io.github.p2vman.lang.Lang;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -12,11 +13,17 @@ public class Event implements Listener {
|
|||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onConnect(PlayerLoginEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (p != null) {
|
||||
Config config = EptaList.config.get();
|
||||
if (config.enable) {
|
||||
if (!((config.skip_to_op && p.isOp()) || EptaList.list.is(p.getName()))) {
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, ChatColor.translateAlternateColorCodes('&', EptaList.mode.kick_msg));
|
||||
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));
|
||||
}).exceptionally(er -> {
|
||||
p.kickPlayer(Lang.LANG.format("err.internal"));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public class WhiteListCommand extends Command {
|
|||
permission_outher = recal.apply(new Permission("eptalist.outher", PermissionDefault.OP));
|
||||
}
|
||||
|
||||
//@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!(args.length > 0)) {
|
||||
|
@ -83,25 +84,22 @@ public class WhiteListCommand extends Command {
|
|||
List<String> info = new ArrayList<>();
|
||||
if (!Utils.len(args, 1)) {
|
||||
sender.sendMessage("Usage: /" + commandLabel + " add <username>");
|
||||
} else if (EptaList.list.addUser(args[1], info)) {
|
||||
sender.sendMessage(Lang.LANG.format("command.add.succes", args[1]));
|
||||
} else {
|
||||
for (String line : info) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
|
||||
}
|
||||
EptaList.list.addUserAsync(args[1], (t) -> sender.sendMessage(ChatColor.translateAlternateColorCodes('&', (String) t)))
|
||||
.thenAccept((d) -> {
|
||||
if (d) sender.sendMessage(Lang.LANG.format("command.add.succes", args[1]));
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "remove": if (testPermission(sender, permission_remove)) {
|
||||
List<String> info = new ArrayList<>();
|
||||
if (!Utils.len(args, 1)) {
|
||||
sender.sendMessage("Usage: /" + commandLabel + " remove <username>");
|
||||
} else if (EptaList.list.removeUser(args[1], info)) {
|
||||
sender.sendMessage(Lang.LANG.format("command.remove.succes", args[1]));
|
||||
} else {
|
||||
for (String line : info) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
|
||||
}
|
||||
EptaList.list.removeUserAsync(args[1], (t) -> sender.sendMessage(ChatColor.translateAlternateColorCodes('&', (String) t)))
|
||||
.thenAccept((d) -> {
|
||||
if (d) sender.sendMessage(Lang.LANG.format("command.remove.succes", args[1]));
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 Moandji Ezana
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -42,7 +42,7 @@ public class Velocity {
|
|||
private Path dataDirectory;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
|
||||
public static Data list;
|
||||
public static Data<String> list;
|
||||
public static Config.Mode mode;
|
||||
public static List<Identifier> identifiers = new ArrayList<>();
|
||||
public static void load() {
|
||||
|
|
|
@ -60,11 +60,8 @@ public class WhiteListCommand implements SimpleCommand {
|
|||
break;
|
||||
}
|
||||
String usernameToAdd = args[1];
|
||||
List<String> infoAdd = new ArrayList<>();
|
||||
if (Velocity.list.addUser(usernameToAdd, infoAdd)) {
|
||||
if (Velocity.list.addUser(usernameToAdd, (t) -> sender.sendMessage(Component.text(t)))) {
|
||||
sender.sendMessage(Component.text(Lang.LANG.format("command.add.succes", usernameToAdd)));
|
||||
} else {
|
||||
infoAdd.forEach(line -> sender.sendMessage(Component.text(line)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -74,11 +71,8 @@ public class WhiteListCommand implements SimpleCommand {
|
|||
break;
|
||||
}
|
||||
String usernameToRemove = args[1];
|
||||
List<String> infoRemove = new ArrayList<>();
|
||||
if (Velocity.list.removeUser(usernameToRemove, infoRemove)) {
|
||||
if (Velocity.list.removeUser(usernameToRemove, (t) -> sender.sendMessage(Component.text(t)))) {
|
||||
sender.sendMessage(Component.text(Lang.LANG.format("command.remove.succes", usernameToRemove)));
|
||||
} else {
|
||||
infoRemove.forEach(line -> sender.sendMessage(Component.text(line)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue