This commit is contained in:
parent
d71cfbafdf
commit
8830ba91c6
|
@ -1,6 +1,52 @@
|
||||||
package io.github.p2vman;
|
package io.github.p2vman;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Identifier implements Comparable<Identifier> {
|
public class Identifier implements Comparable<Identifier> {
|
||||||
|
public static class Adapter extends TypeAdapter<Identifier> {
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, Identifier value) throws IOException {
|
||||||
|
out.value(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Identifier read(JsonReader in) throws IOException {
|
||||||
|
JsonToken token = in.peek();
|
||||||
|
|
||||||
|
if (token == JsonToken.STRING) {
|
||||||
|
return new Identifier(in.nextString());
|
||||||
|
} else if (token == JsonToken.BEGIN_OBJECT) {
|
||||||
|
in.beginObject();
|
||||||
|
String namespace = "minecraft";
|
||||||
|
String path = null;
|
||||||
|
|
||||||
|
while (in.hasNext()) {
|
||||||
|
String name = in.nextName();
|
||||||
|
if (name.equals("namespace")) {
|
||||||
|
namespace = in.nextString();
|
||||||
|
} else if (name.equals("path")) {
|
||||||
|
path = in.nextString();
|
||||||
|
} else {
|
||||||
|
in.skipValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
in.endObject();
|
||||||
|
if (path == null) {
|
||||||
|
throw new IOException("Missing 'path' in Identifier object");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Identifier.of(namespace, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IOException("Unexpected token: " + token);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static final char NAMESPACE_SEPARATOR = ':';
|
public static final char NAMESPACE_SEPARATOR = ':';
|
||||||
public static final String DEFAULT_NAMESPACE = "minecraft";
|
public static final String DEFAULT_NAMESPACE = "minecraft";
|
||||||
private final String namespace;
|
private final String namespace;
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package io.github.p2vman;
|
package io.github.p2vman;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
public class Static {
|
public class Static {
|
||||||
public static final Gson GSON = new Gson();
|
public static final Gson GSON = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Identifier.class, new Identifier.Adapter())
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package io.github.p2vman.lang;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface Formatter {
|
||||||
|
String format(String string, Object... args);
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package io.github.p2vman.lang;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface Lang extends BiConsumer<String, String>, Consumer<InputStream>, BiFunction<JsonElement, Stack<String>, Void> {
|
||||||
|
Lang LANG = new Language();
|
||||||
|
String get(String id);
|
||||||
|
String getOrDefult(String id, String defult);
|
||||||
|
default String getOrDefult(String id) {
|
||||||
|
return getOrDefult(id, id);
|
||||||
|
}
|
||||||
|
boolean has(String id);
|
||||||
|
void clear();
|
||||||
|
String format(String id, Object... args);
|
||||||
|
Formatter setFormater(Formatter formatter);
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package io.github.p2vman.lang;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.github.p2vman.Static;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
public class Language implements Lang, BiConsumer<String, String>, Consumer<InputStream>, BiFunction<JsonElement, Stack<String>, Void> {
|
||||||
|
private Formatter formatter = String::format;
|
||||||
|
private Map<String, String> map;
|
||||||
|
private static final Pattern UNSUPPORTED_FORMAT_PATTERN = Pattern.compile("%(\\d+\\$)?[\\d.]*[df]");
|
||||||
|
public Language() {
|
||||||
|
map = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(String id) {
|
||||||
|
return map.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOrDefult(String id) {
|
||||||
|
return map.getOrDefault(id, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOrDefult(String id, String defult) {
|
||||||
|
return map.getOrDefault(id, defult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(String s, String s2) {
|
||||||
|
map.put(s, s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean has(String id) {
|
||||||
|
return map.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(InputStream stream) {
|
||||||
|
JsonObject jsonObject = Static.GSON.fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), JsonObject.class);
|
||||||
|
|
||||||
|
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||||
|
Stack<String> stack = new Stack<>();
|
||||||
|
stack.push(entry.getKey());
|
||||||
|
apply(entry.getValue(), stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void apply(JsonElement jsonElement, Stack<String> strings) {
|
||||||
|
if (jsonElement.isJsonObject()) {
|
||||||
|
for (Map.Entry<String, JsonElement> entry : jsonElement.getAsJsonObject().entrySet()) {
|
||||||
|
Stack<String> strings2 = new Stack<>();
|
||||||
|
strings2.addAll(strings);
|
||||||
|
strings2.push(entry.getKey());
|
||||||
|
apply(entry.getValue(), strings2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.accept(String.join(".", strings), UNSUPPORTED_FORMAT_PATTERN.matcher(jsonElement.getAsString()).replaceAll("%$1s"));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(String id, Object... args) {
|
||||||
|
return formatter.format(getOrDefult(id), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Formatter setFormatter(Formatter formatter) {
|
||||||
|
this.formatter = formatter;
|
||||||
|
return formatter;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,6 @@ package io.github.p2vman.updater;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,10 +26,16 @@ public class Updater {
|
||||||
private static final String API_URL = "https://api.spiget.org/v2/resources/";
|
private static final String API_URL = "https://api.spiget.org/v2/resources/";
|
||||||
private static final String URL = "https://www.spigotmc.org/";
|
private static final String URL = "https://www.spigotmc.org/";
|
||||||
private static final String SPIGOT_SIDE_API = "https://api.spigotmc.org/legacy/";
|
private static final String SPIGOT_SIDE_API = "https://api.spigotmc.org/legacy/";
|
||||||
|
private JsonObject object;
|
||||||
|
|
||||||
|
public JsonObject getJson() {
|
||||||
|
return object.deepCopy();
|
||||||
|
}
|
||||||
|
|
||||||
public Updater() {
|
public Updater() {
|
||||||
try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(Updater.class.getClassLoader().getResourceAsStream("updater.json")))) {
|
try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(Updater.class.getClassLoader().getResourceAsStream("updater.json")))) {
|
||||||
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
|
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
|
||||||
|
this.object = jsonObject;
|
||||||
id = jsonObject.get("id").getAsString();
|
id = jsonObject.get("id").getAsString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -6,15 +6,19 @@ import io.github.p2vman.Static;
|
||||||
import io.github.p2vman.Utils;
|
import io.github.p2vman.Utils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
public Identifier command = new Identifier("command", "eptalist");
|
||||||
|
@SerializedName("updater")
|
||||||
|
public boolean auto_update_check = true;
|
||||||
public boolean enable = false;
|
public boolean enable = false;
|
||||||
public boolean skip_to_op = true;
|
public boolean skip_to_op = true;
|
||||||
public Identifier curent = new Identifier("whitelist", "base");
|
public Identifier curent = new Identifier("whitelist", "base");
|
||||||
|
@SerializedName("lang")
|
||||||
|
public String language = "en";
|
||||||
public Mode[] modes = new Mode[] {
|
public Mode[] modes = new Mode[] {
|
||||||
new Mode(
|
new Mode(
|
||||||
new Identifier(
|
new Identifier(
|
||||||
|
@ -67,12 +71,12 @@ public class Config {
|
||||||
try {
|
try {
|
||||||
if (!config.exists()) {
|
if (!config.exists()) {
|
||||||
this.cfg = new Config();
|
this.cfg = new Config();
|
||||||
try (FileWriter writer =new FileWriter(this.config)) {
|
try (FileWriter writer =new FileWriter(this.config, StandardCharsets.UTF_8)) {
|
||||||
Static.GSON.toJson(cfg, writer);
|
Static.GSON.toJson(cfg, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try (FileReader reader = new FileReader(this.config)) {
|
try (FileReader reader = new FileReader(this.config, StandardCharsets.UTF_8)) {
|
||||||
cfg = Static.GSON.fromJson(reader, Config.class);
|
cfg = Static.GSON.fromJson(reader, Config.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +86,7 @@ public class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try (FileWriter writer = new FileWriter(this.config)) {
|
try (FileWriter writer = new FileWriter(this.config, StandardCharsets.UTF_8)) {
|
||||||
Static.GSON.toJson(cfg, writer);
|
Static.GSON.toJson(cfg, writer);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.eptalist.storge;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import io.github.p2vman.Static;
|
import io.github.p2vman.Static;
|
||||||
|
import io.github.p2vman.lang.Lang;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -110,7 +111,7 @@ public class Json extends ArrayList<String> implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean removeUser(String name, List<String> info) {
|
public boolean removeUser(String name, List<String> info) {
|
||||||
if (!is(name)) {
|
if (!is(name)) {
|
||||||
info.add("&r" + name + "is not in the whitelist");
|
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return remove(name);
|
return remove(name);
|
||||||
|
@ -119,7 +120,7 @@ public class Json extends ArrayList<String> implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean addUser(String name, List<String> info) {
|
public boolean addUser(String name, List<String> info) {
|
||||||
if (is(name)) {
|
if (is(name)) {
|
||||||
info.add("&r" + name + "is already on the whitelist");
|
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return add(name);
|
return add(name);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.eptalist.storge;
|
package org.eptalist.storge;
|
||||||
|
|
||||||
|
import io.github.p2vman.lang.Lang;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -44,7 +46,7 @@ public class Mysql implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean removeUser(String name, List<String> info) {
|
public boolean removeUser(String name, List<String> info) {
|
||||||
if (!is(name)) {
|
if (!is(name)) {
|
||||||
info.add("&r" + name + "is not in the whitelist");
|
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -53,7 +55,7 @@ public class Mysql implements Data<String> {
|
||||||
return statement.executeUpdate() > 0;
|
return statement.executeUpdate() > 0;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
info.add("&rThere was an error in the database");
|
info.add(Lang.LANG.format("err.db"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +65,7 @@ public class Mysql implements Data<String> {
|
||||||
try {
|
try {
|
||||||
if (connection.isClosed()) {
|
if (connection.isClosed()) {
|
||||||
connection = DriverManager.getConnection(String.format((String) this.data.get("file")));
|
connection = DriverManager.getConnection(String.format((String) this.data.get("file")));
|
||||||
info.add("&6The database has been reconnected");
|
info.add(Lang.LANG.format("storge.reconnect"));
|
||||||
}
|
}
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT user_name FROM "+this.teable+" WHERE "+this.i+" = ?");
|
PreparedStatement statement = connection.prepareStatement("SELECT user_name FROM "+this.teable+" WHERE "+this.i+" = ?");
|
||||||
statement.setString(1, name);
|
statement.setString(1, name);
|
||||||
|
@ -71,7 +73,7 @@ public class Mysql implements Data<String> {
|
||||||
return resultSet.next();
|
return resultSet.next();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
info.add("&rThere was an error in the database");
|
info.add(Lang.LANG.format("err.db"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +97,7 @@ public class Mysql implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean addUser(String name, List<String> info) {
|
public boolean addUser(String name, List<String> info) {
|
||||||
if (is(name)) {
|
if (is(name)) {
|
||||||
info.add("&r" + name + "is already on the whitelist");
|
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -104,7 +106,7 @@ public class Mysql implements Data<String> {
|
||||||
return statement.executeUpdate() > 0;
|
return statement.executeUpdate() > 0;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
info.add("&rThere was an error in the database");
|
info.add(Lang.LANG.format("err.db"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.eptalist.storge;
|
package org.eptalist.storge;
|
||||||
|
|
||||||
|
import io.github.p2vman.lang.Lang;
|
||||||
import io.github.p2vman.nbt.NbtIo;
|
import io.github.p2vman.nbt.NbtIo;
|
||||||
import io.github.p2vman.nbt.tag.Tag;
|
import io.github.p2vman.nbt.tag.Tag;
|
||||||
import io.github.p2vman.nbt.tag.TagCompound;
|
import io.github.p2vman.nbt.tag.TagCompound;
|
||||||
|
@ -145,7 +146,7 @@ public class NBT extends ArrayList<String> implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean removeUser(String name, List<String> info) {
|
public boolean removeUser(String name, List<String> info) {
|
||||||
if (!is(name)) {
|
if (!is(name)) {
|
||||||
info.add("&r" + name + "is not in the whitelist");
|
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return remove(name);
|
return remove(name);
|
||||||
|
@ -154,7 +155,7 @@ public class NBT extends ArrayList<String> implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean addUser(String name, List<String> info) {
|
public boolean addUser(String name, List<String> info) {
|
||||||
if (is(name)) {
|
if (is(name)) {
|
||||||
info.add("&r" + name + "is already on the whitelist");
|
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return add(name);
|
return add(name);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.eptalist.storge;
|
package org.eptalist.storge;
|
||||||
|
|
||||||
|
import io.github.p2vman.lang.Lang;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,7 +47,7 @@ public class Sqlite implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean removeUser(String name, List<String> info) {
|
public boolean removeUser(String name, List<String> info) {
|
||||||
if (!is(name)) {
|
if (!is(name)) {
|
||||||
info.add("&r" + name + "is not in the whitelist");
|
info.add(Lang.LANG.format("storge.remove.not.in", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -54,7 +56,7 @@ public class Sqlite implements Data<String> {
|
||||||
return statement.executeUpdate() > 0;
|
return statement.executeUpdate() > 0;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
info.add("&rThere was an error in the database");
|
info.add(Lang.LANG.format("err.db"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +66,7 @@ public class Sqlite implements Data<String> {
|
||||||
try {
|
try {
|
||||||
if (connection.isClosed()) {
|
if (connection.isClosed()) {
|
||||||
connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s.db", (String) this.data.get("file")));
|
connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s.db", (String) this.data.get("file")));
|
||||||
info.add("&6The database has been reconnected");
|
info.add(Lang.LANG.format("storge.reconnect"));
|
||||||
}
|
}
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT "+this.i+" FROM "+this.teable+" WHERE "+this.i+" = ?");
|
PreparedStatement statement = connection.prepareStatement("SELECT "+this.i+" FROM "+this.teable+" WHERE "+this.i+" = ?");
|
||||||
statement.setString(1, name);
|
statement.setString(1, name);
|
||||||
|
@ -72,7 +74,7 @@ public class Sqlite implements Data<String> {
|
||||||
return resultSet.next();
|
return resultSet.next();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
info.add("&rThere was an error in the database");
|
info.add(Lang.LANG.format("err.db"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,7 @@ public class Sqlite implements Data<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean addUser(String name, List<String> info) {
|
public boolean addUser(String name, List<String> info) {
|
||||||
if (is(name)) {
|
if (is(name)) {
|
||||||
info.add("&r" + name + "is already on the whitelist");
|
info.add(Lang.LANG.format("storge.add.is.already", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -105,7 +107,7 @@ public class Sqlite implements Data<String> {
|
||||||
return statement.executeUpdate() > 0;
|
return statement.executeUpdate() > 0;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
info.add("&rThere was an error in the database");
|
info.add(Lang.LANG.format("err.db"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"storge": {
|
||||||
|
"remove": {
|
||||||
|
"not.in": "&4 %s is not in the whitelist"
|
||||||
|
},
|
||||||
|
"add": {
|
||||||
|
"is.already": "&4 %s is already on the whitelist"
|
||||||
|
},
|
||||||
|
"reconnect": "&6The database has been reconnected"
|
||||||
|
},
|
||||||
|
"err": {
|
||||||
|
"db": "&4There was an error in the database"
|
||||||
|
},
|
||||||
|
"command": {
|
||||||
|
"reload": {
|
||||||
|
"succes": "Configuration reloaded successfully.",
|
||||||
|
"failed": "&4Failed to reload the configuration."
|
||||||
|
},
|
||||||
|
"remove": {
|
||||||
|
"succes": "User removed from the whitelist: %s"
|
||||||
|
},
|
||||||
|
"add": {
|
||||||
|
"succes": "User added to the whitelist: %s"
|
||||||
|
},
|
||||||
|
"mode": {
|
||||||
|
"succes": "Mode set to: %s",
|
||||||
|
"invalid.id": "&4Invalid mode ID!"
|
||||||
|
},
|
||||||
|
"on": "Whitelist enabled.",
|
||||||
|
"off": "Whitelist disabled."
|
||||||
|
},
|
||||||
|
"perm": {
|
||||||
|
"throw": "&4You don't have permission to perform this command."
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,12 @@
|
||||||
{
|
{
|
||||||
"id": "122225",
|
"id": "122225",
|
||||||
"source": "https://github.com/p2vman/EptaListProject"
|
"info": {
|
||||||
|
"authors": [
|
||||||
|
"p2vman"
|
||||||
|
],
|
||||||
|
"urls": {
|
||||||
|
"source": "https://github.com/p2vman/EptaListProject",
|
||||||
|
"discord": "https://discord.gg/UdSXf4tpUF"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,6 @@ package org.eptalist.bounge;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.p2vman.Identifier;
|
import io.github.p2vman.Identifier;
|
||||||
import io.github.p2vman.Static;
|
|
||||||
import io.github.p2vman.profiling.ExempleProfiler;
|
import io.github.p2vman.profiling.ExempleProfiler;
|
||||||
import io.github.p2vman.profiling.Profiler;
|
import io.github.p2vman.profiling.Profiler;
|
||||||
import io.github.p2vman.updater.Updater;
|
import io.github.p2vman.updater.Updater;
|
||||||
|
@ -51,6 +50,14 @@ public final class Boungecord extends Plugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
File data = getDataFolder();
|
||||||
|
if (!data.exists()) {
|
||||||
|
data.mkdirs();
|
||||||
|
}
|
||||||
|
config = new Config.ConfigContainer(new File(data, "wh.json"));
|
||||||
|
load();
|
||||||
|
if (config.get().auto_update_check)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
Updater updater = Updater.getInstance();
|
Updater updater = Updater.getInstance();
|
||||||
JsonObject obj = updater.getLasted();
|
JsonObject obj = updater.getLasted();
|
||||||
|
@ -65,13 +72,8 @@ public final class Boungecord extends Plugin {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
File data = getDataFolder();
|
|
||||||
if (!data.exists()) {
|
|
||||||
data.mkdirs();
|
|
||||||
}
|
}
|
||||||
config = new Config.ConfigContainer(new File(data, "wh.json"));
|
|
||||||
|
|
||||||
load();
|
|
||||||
Metrics metrics = new Metrics(this, Constants.bstats_id);
|
Metrics metrics = new Metrics(this, Constants.bstats_id);
|
||||||
|
|
||||||
metrics.addCustomChart(new SimplePie("data_type", () -> mode.storage));
|
metrics.addCustomChart(new SimplePie("data_type", () -> mode.storage));
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package org.eptalist.bounge;
|
package org.eptalist.bounge;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import io.github.p2vman.Identifier;
|
import io.github.p2vman.Identifier;
|
||||||
|
import io.github.p2vman.updater.Updater;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
@ -9,14 +12,14 @@ import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class WhiteListCommand extends Command implements TabExecutor {
|
public class WhiteListCommand extends Command implements TabExecutor {
|
||||||
private final String[] w1 = {"off", "on", "add", "remove", "list", "help", "mode", "reload"};
|
private final String[] w1 = {"off", "on", "add", "remove", "list", "help", "mode", "reload","info"};
|
||||||
|
|
||||||
public WhiteListCommand() {
|
public WhiteListCommand() {
|
||||||
super("eptalist");
|
super(Boungecord.config.get().command.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,6 +112,16 @@ public class WhiteListCommand extends Command implements TabExecutor {
|
||||||
sender.sendMessage(new TextComponent("Failed to reload the configuration."));
|
sender.sendMessage(new TextComponent("Failed to reload the configuration."));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "info":
|
||||||
|
{
|
||||||
|
JsonObject object = Updater.getInstance().getJson().getAsJsonObject("info");
|
||||||
|
sender.sendMessage(new TextComponent("links:"));
|
||||||
|
for (Map.Entry<String, JsonElement> entry : object.getAsJsonObject("urls").entrySet()) {
|
||||||
|
sender.sendMessage(new TextComponent(entry.getKey()+": "+entry.getValue().getAsString()));
|
||||||
|
}
|
||||||
|
sender.sendMessage(new TextComponent());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(new TextComponent("Unknown command. Use /eptalist help for the list of commands."));
|
sender.sendMessage(new TextComponent("Unknown command. Use /eptalist help for the list of commands."));
|
||||||
|
|
|
@ -7,6 +7,7 @@ plugins {
|
||||||
import de.undercouch.gradle.tasks.download.Download
|
import de.undercouch.gradle.tasks.download.Download
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
plugins.apply("java")
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
version = 1.5
|
version = 1.6
|
|
@ -1,9 +1,11 @@
|
||||||
package org.eptalist.spigot;
|
package org.eptalist.spigot;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import io.github.p2vman.lang.Lang;
|
||||||
import io.github.p2vman.profiling.ExempleProfiler;
|
import io.github.p2vman.profiling.ExempleProfiler;
|
||||||
import io.github.p2vman.profiling.Profiler;
|
import io.github.p2vman.profiling.Profiler;
|
||||||
import io.github.p2vman.updater.Updater;
|
import io.github.p2vman.updater.Updater;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.eptalist.Config;
|
import org.eptalist.Config;
|
||||||
import io.github.p2vman.Identifier;
|
import io.github.p2vman.Identifier;
|
||||||
import org.eptalist.Constants;
|
import org.eptalist.Constants;
|
||||||
|
@ -37,6 +39,13 @@ public final class EptaList extends JavaPlugin {
|
||||||
profiler.push("load");
|
profiler.push("load");
|
||||||
config.load();
|
config.load();
|
||||||
identifiers.clear();
|
identifiers.clear();
|
||||||
|
Lang.LANG.clear();
|
||||||
|
Lang.LANG.setFormater(((string, args) -> ChatColor.translateAlternateColorCodes('&', String.format(string, args))));
|
||||||
|
try {
|
||||||
|
Lang.LANG.accept(EptaList.class.getResourceAsStream("/res/"+config.get().language+".json"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
for (Config.Mode mode1 : config.get().modes) {
|
for (Config.Mode mode1 : config.get().modes) {
|
||||||
identifiers.add(mode1.id);
|
identifiers.add(mode1.id);
|
||||||
}
|
}
|
||||||
|
@ -57,6 +66,17 @@ public final class EptaList extends JavaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
profiler.push("init");
|
||||||
|
metrics = new Metrics(this, Constants.bstats_id);
|
||||||
|
|
||||||
|
File data = getDataFolder();
|
||||||
|
if (!data.exists()) {
|
||||||
|
data.mkdirs();
|
||||||
|
}
|
||||||
|
config = new Config.ConfigContainer(new File(data, "wh.json"));
|
||||||
|
load();
|
||||||
|
|
||||||
|
if (config.get().auto_update_check) {
|
||||||
try {
|
try {
|
||||||
Updater updater = Updater.getInstance();
|
Updater updater = Updater.getInstance();
|
||||||
JsonObject obj = updater.getLasted();
|
JsonObject obj = updater.getLasted();
|
||||||
|
@ -71,26 +91,16 @@ public final class EptaList extends JavaPlugin {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
profiler.push("init");
|
|
||||||
metrics = new Metrics(this, Constants.bstats_id);
|
|
||||||
|
|
||||||
File data = getDataFolder();
|
|
||||||
if (!data.exists()) {
|
|
||||||
data.mkdirs();
|
|
||||||
}
|
}
|
||||||
config = new Config.ConfigContainer(new File(data, "wh.json"));
|
|
||||||
load();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
commandMapField.setAccessible(true);
|
commandMapField.setAccessible(true);
|
||||||
CommandMap map = (CommandMap)commandMapField.get(Bukkit.getServer());
|
CommandMap map = (CommandMap)commandMapField.get(Bukkit.getServer());
|
||||||
|
|
||||||
Command command = new WhiteListCommand();
|
Command command = new WhiteListCommand(config.get().command);
|
||||||
|
|
||||||
map.register("minecraft", command);
|
map.register(config.get().command.getNamespace(), command);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -98,6 +108,7 @@ public final class EptaList extends JavaPlugin {
|
||||||
getServer().getPluginManager().registerEvents(new Event(), this);
|
getServer().getPluginManager().registerEvents(new Event(), this);
|
||||||
metrics.addCustomChart(new SimplePie("data_type", () -> mode.storage));
|
metrics.addCustomChart(new SimplePie("data_type", () -> mode.storage));
|
||||||
LOGGER.log(Level.INFO, String.format("Init Plugin %sms", profiler.getElapsedTimeAndRemove(profiler.pop())));
|
LOGGER.log(Level.INFO, String.format("Init Plugin %sms", profiler.getElapsedTimeAndRemove(profiler.pop())));
|
||||||
|
System.out.println(Lang.LANG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package org.eptalist.spigot;
|
package org.eptalist.spigot;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.github.p2vman.lang.Lang;
|
||||||
|
import io.github.p2vman.updater.Updater;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -27,7 +31,8 @@ public class WhiteListCommand extends Command {
|
||||||
"help",
|
"help",
|
||||||
"mode",
|
"mode",
|
||||||
"kick_nolisted",
|
"kick_nolisted",
|
||||||
"reload"
|
"reload",
|
||||||
|
"info"
|
||||||
};
|
};
|
||||||
private final Permission permission_enable;
|
private final Permission permission_enable;
|
||||||
private final Permission permission_add;
|
private final Permission permission_add;
|
||||||
|
@ -38,8 +43,8 @@ public class WhiteListCommand extends Command {
|
||||||
private final Permission permission_list;
|
private final Permission permission_list;
|
||||||
|
|
||||||
|
|
||||||
public WhiteListCommand() {
|
public WhiteListCommand(Identifier identifier) {
|
||||||
super("eptalist");
|
super(identifier.getPath());
|
||||||
Function<Permission, Permission> recal = (p) -> {
|
Function<Permission, Permission> recal = (p) -> {
|
||||||
p.recalculatePermissibles();
|
p.recalculatePermissibles();
|
||||||
return p;
|
return p;
|
||||||
|
@ -64,13 +69,13 @@ public class WhiteListCommand extends Command {
|
||||||
case "off": if (testPermission(sender, permission_enable)) {
|
case "off": if (testPermission(sender, permission_enable)) {
|
||||||
EptaList.config.get().enable = false;
|
EptaList.config.get().enable = false;
|
||||||
EptaList.config.save();
|
EptaList.config.save();
|
||||||
sender.sendMessage("Whitelist disabled.");
|
sender.sendMessage(Lang.LANG.format("command.off"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "on": if (testPermission(sender, permission_enable)) {
|
case "on": if (testPermission(sender, permission_enable)) {
|
||||||
EptaList.config.get().enable = true;
|
EptaList.config.get().enable = true;
|
||||||
EptaList.config.save();
|
EptaList.config.save();
|
||||||
sender.sendMessage("Whitelist enabled.");
|
sender.sendMessage(Lang.LANG.format("command.on"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "add": if (testPermission(sender, permission_add)) {
|
case "add": if (testPermission(sender, permission_add)) {
|
||||||
|
@ -78,7 +83,7 @@ public class WhiteListCommand extends Command {
|
||||||
if (!Utils.len(args, 1)) {
|
if (!Utils.len(args, 1)) {
|
||||||
sender.sendMessage("Usage: /" + commandLabel + " add <username>");
|
sender.sendMessage("Usage: /" + commandLabel + " add <username>");
|
||||||
} else if (EptaList.list.addUser(args[1], info)) {
|
} else if (EptaList.list.addUser(args[1], info)) {
|
||||||
sender.sendMessage("User added to the whitelist: " + args[1]);
|
sender.sendMessage(Lang.LANG.format("command.add.succes", args[1]));
|
||||||
} else {
|
} else {
|
||||||
for (String line : info) {
|
for (String line : info) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
|
||||||
|
@ -91,7 +96,7 @@ public class WhiteListCommand extends Command {
|
||||||
if (!Utils.len(args, 1)) {
|
if (!Utils.len(args, 1)) {
|
||||||
sender.sendMessage("Usage: /" + commandLabel + " remove <username>");
|
sender.sendMessage("Usage: /" + commandLabel + " remove <username>");
|
||||||
} else if (EptaList.list.removeUser(args[1], info)) {
|
} else if (EptaList.list.removeUser(args[1], info)) {
|
||||||
sender.sendMessage("User removed from the whitelist: " + args[1]);
|
sender.sendMessage(Lang.LANG.format("command.remove.succes", args[1]));
|
||||||
} else {
|
} else {
|
||||||
for (String line : info) {
|
for (String line : info) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
|
||||||
|
@ -112,9 +117,9 @@ public class WhiteListCommand extends Command {
|
||||||
EptaList.config.get().curent = id;
|
EptaList.config.get().curent = id;
|
||||||
EptaList.config.save();
|
EptaList.config.save();
|
||||||
EptaList.load();
|
EptaList.load();
|
||||||
sender.sendMessage("Mode set to: " + id);
|
sender.sendMessage(Lang.LANG.format("command.mode.succes", id));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Invalid mode ID!");
|
sender.sendMessage(Lang.LANG.format("command.mode.invalid.id"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,13 +149,23 @@ public class WhiteListCommand extends Command {
|
||||||
case "reload": if (testPermission(sender, permission_reload)) {
|
case "reload": if (testPermission(sender, permission_reload)) {
|
||||||
try {
|
try {
|
||||||
EptaList.load();
|
EptaList.load();
|
||||||
sender.sendMessage("Configuration reloaded successfully.");
|
sender.sendMessage(Lang.LANG.format("command.reload.succes"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sender.sendMessage("Failed to reload the configuration.");
|
sender.sendMessage(Lang.LANG.format("command.reload.failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "info":
|
||||||
|
{
|
||||||
|
JsonObject object = Updater.getInstance().getJson().getAsJsonObject("info");
|
||||||
|
sender.sendMessage("links:");
|
||||||
|
for (Map.Entry<String, JsonElement> entry : object.getAsJsonObject("urls").entrySet()) {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2"+entry.getKey()+"&f: &4"+entry.getValue().getAsString()));
|
||||||
|
}
|
||||||
|
sender.sendMessage("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +247,7 @@ public class WhiteListCommand extends Command {
|
||||||
if (target.hasPermission(permission.getName())) {
|
if (target.hasPermission(permission.getName())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
target.sendMessage(ChatColor.RED + "You don't have permission to perform this command.");
|
target.sendMessage(Lang.LANG.format("perm.throw"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,15 @@ public class Velocity {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Velocity(ProxyServer server, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
|
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();
|
||||||
|
}
|
||||||
|
config = new Config.ConfigContainer(new File(dataDirectory.toFile(), "config.json"));
|
||||||
|
load();
|
||||||
|
if (config.get().auto_update_check) {
|
||||||
try {
|
try {
|
||||||
Updater updater = Updater.getInstance();
|
Updater updater = Updater.getInstance();
|
||||||
JsonObject obj = updater.getLasted();
|
JsonObject obj = updater.getLasted();
|
||||||
|
@ -82,16 +91,9 @@ public class Velocity {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
profiler.push("init");
|
|
||||||
this.metricsFactory = metricsFactory;
|
|
||||||
this.dataDirectory = dataDirectory;
|
|
||||||
if (!Files.exists(dataDirectory)) {
|
|
||||||
dataDirectory.toFile().mkdirs();
|
|
||||||
}
|
}
|
||||||
config = new Config.ConfigContainer(new File(dataDirectory.toFile(), "config.json"));
|
|
||||||
load();
|
|
||||||
CommandManager commandManager = server.getCommandManager();
|
CommandManager commandManager = server.getCommandManager();
|
||||||
commandManager.register("eptalist", new WhiteListCommand(logger));
|
commandManager.register(config.get().command.getPath(), new WhiteListCommand(logger));
|
||||||
LOGGER.log(Level.INFO, String.format("Load Plugin Configuration %sms", profiler.getElapsedTimeAndRemove(profiler.pop())));
|
LOGGER.log(Level.INFO, String.format("Load Plugin Configuration %sms", profiler.getElapsedTimeAndRemove(profiler.pop())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue