This commit is contained in:
p2vman 2025-02-21 07:48:03 +02:00
parent d71cfbafdf
commit 8830ba91c6
20 changed files with 362 additions and 89 deletions

View File

@ -1,6 +1,52 @@
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 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 String DEFAULT_NAMESPACE = "minecraft";
private final String namespace;

View File

@ -1,7 +1,11 @@
package io.github.p2vman;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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();
}

View File

@ -0,0 +1,6 @@
package io.github.p2vman.lang;
@FunctionalInterface
public interface Formatter {
String format(String string, Object... args);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -2,7 +2,6 @@ package io.github.p2vman.updater;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import java.io.BufferedReader;
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 URL = "https://www.spigotmc.org/";
private static final String SPIGOT_SIDE_API = "https://api.spigotmc.org/legacy/";
private JsonObject object;
public JsonObject getJson() {
return object.deepCopy();
}
public Updater() {
try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(Updater.class.getClassLoader().getResourceAsStream("updater.json")))) {
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
this.object = jsonObject;
id = jsonObject.get("id").getAsString();
} catch (Exception e) {
e.printStackTrace();

View File

@ -6,15 +6,19 @@ import io.github.p2vman.Static;
import io.github.p2vman.Utils;
import java.io.*;
import java.util.ArrayList;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Config {
public Identifier command = new Identifier("command", "eptalist");
@SerializedName("updater")
public boolean auto_update_check = true;
public boolean enable = false;
public boolean skip_to_op = true;
public Identifier curent = new Identifier("whitelist", "base");
@SerializedName("lang")
public String language = "en";
public Mode[] modes = new Mode[] {
new Mode(
new Identifier(
@ -67,12 +71,12 @@ public class Config {
try {
if (!config.exists()) {
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);
}
}
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);
}
}
@ -82,7 +86,7 @@ public class Config {
}
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);
} catch (Exception e) {
e.printStackTrace();

View File

@ -3,6 +3,7 @@ package org.eptalist.storge;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import io.github.p2vman.Static;
import io.github.p2vman.lang.Lang;
import java.io.*;
import java.nio.charset.StandardCharsets;
@ -110,7 +111,7 @@ public class Json extends ArrayList<String> implements Data<String> {
@Override
public boolean removeUser(String name, List<String> info) {
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 remove(name);
@ -119,7 +120,7 @@ public class Json extends ArrayList<String> implements Data<String> {
@Override
public boolean addUser(String name, List<String> info) {
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 add(name);

View File

@ -1,5 +1,7 @@
package org.eptalist.storge;
import io.github.p2vman.lang.Lang;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@ -44,7 +46,7 @@ public class Mysql implements Data<String> {
@Override
public boolean removeUser(String name, List<String> info) {
if (!is(name)) {
info.add("&r" + name + "is not in the whitelist");
info.add(Lang.LANG.format("storge.remove.not.in", name));
return false;
}
try {
@ -53,7 +55,7 @@ public class Mysql implements Data<String> {
return statement.executeUpdate() > 0;
} catch (SQLException e) {
e.printStackTrace();
info.add("&rThere was an error in the database");
info.add(Lang.LANG.format("err.db"));
return false;
}
}
@ -63,7 +65,7 @@ public class Mysql implements Data<String> {
try {
if (connection.isClosed()) {
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+" = ?");
statement.setString(1, name);
@ -71,7 +73,7 @@ public class Mysql implements Data<String> {
return resultSet.next();
} catch (SQLException e) {
e.printStackTrace();
info.add("&rThere was an error in the database");
info.add(Lang.LANG.format("err.db"));
return false;
}
}
@ -95,7 +97,7 @@ public class Mysql implements Data<String> {
@Override
public boolean addUser(String name, List<String> info) {
if (is(name)) {
info.add("&r" + name + "is already on the whitelist");
info.add(Lang.LANG.format("storge.add.is.already", name));
return false;
}
try {
@ -104,7 +106,7 @@ public class Mysql implements Data<String> {
return statement.executeUpdate() > 0;
} catch (SQLException e) {
e.printStackTrace();
info.add("&rThere was an error in the database");
info.add(Lang.LANG.format("err.db"));
return false;
}
}

View File

@ -1,5 +1,6 @@
package org.eptalist.storge;
import io.github.p2vman.lang.Lang;
import io.github.p2vman.nbt.NbtIo;
import io.github.p2vman.nbt.tag.Tag;
import io.github.p2vman.nbt.tag.TagCompound;
@ -145,7 +146,7 @@ public class NBT extends ArrayList<String> implements Data<String> {
@Override
public boolean removeUser(String name, List<String> info) {
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 remove(name);
@ -154,7 +155,7 @@ public class NBT extends ArrayList<String> implements Data<String> {
@Override
public boolean addUser(String name, List<String> info) {
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 add(name);

View File

@ -1,5 +1,7 @@
package org.eptalist.storge;
import io.github.p2vman.lang.Lang;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@ -45,7 +47,7 @@ public class Sqlite implements Data<String> {
@Override
public boolean removeUser(String name, List<String> info) {
if (!is(name)) {
info.add("&r" + name + "is not in the whitelist");
info.add(Lang.LANG.format("storge.remove.not.in", name));
return false;
}
try {
@ -54,7 +56,7 @@ public class Sqlite implements Data<String> {
return statement.executeUpdate() > 0;
} catch (SQLException e) {
e.printStackTrace();
info.add("&rThere was an error in the database");
info.add(Lang.LANG.format("err.db"));
return false;
}
}
@ -64,7 +66,7 @@ public class Sqlite implements Data<String> {
try {
if (connection.isClosed()) {
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+" = ?");
statement.setString(1, name);
@ -72,7 +74,7 @@ public class Sqlite implements Data<String> {
return resultSet.next();
} catch (SQLException e) {
e.printStackTrace();
info.add("&rThere was an error in the database");
info.add(Lang.LANG.format("err.db"));
return false;
}
}
@ -96,7 +98,7 @@ public class Sqlite implements Data<String> {
@Override
public boolean addUser(String name, List<String> info) {
if (is(name)) {
info.add("&r" + name + "is already on the whitelist");
info.add(Lang.LANG.format("storge.add.is.already", name));
return false;
}
try {
@ -105,7 +107,7 @@ public class Sqlite implements Data<String> {
return statement.executeUpdate() > 0;
} catch (SQLException e) {
e.printStackTrace();
info.add("&rThere was an error in the database");
info.add(Lang.LANG.format("err.db"));
return false;
}
}

View File

@ -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."
}
}

View File

@ -1,4 +1,12 @@
{
"id": "122225",
"source": "https://github.com/p2vman/EptaListProject"
"info": {
"authors": [
"p2vman"
],
"urls": {
"source": "https://github.com/p2vman/EptaListProject",
"discord": "https://discord.gg/UdSXf4tpUF"
}
}
}

View File

@ -2,7 +2,6 @@ package org.eptalist.bounge;
import com.google.gson.JsonObject;
import io.github.p2vman.Identifier;
import io.github.p2vman.Static;
import io.github.p2vman.profiling.ExempleProfiler;
import io.github.p2vman.profiling.Profiler;
import io.github.p2vman.updater.Updater;
@ -51,27 +50,30 @@ public final class Boungecord extends Plugin {
@Override
public void onEnable() {
try {
Updater updater = Updater.getInstance();
JsonObject obj = updater.getLasted();
if (!getDescription().getVersion().equals(obj.get("name").getAsString())) {
LOGGER.log(Level.WARNING, "---------- Outdated Version ----------");
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "new version:");
LOGGER.log(Level.WARNING, updater.getVersionUrl());
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "---------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
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 {
Updater updater = Updater.getInstance();
JsonObject obj = updater.getLasted();
if (!getDescription().getVersion().equals(obj.get("name").getAsString())) {
LOGGER.log(Level.WARNING, "---------- Outdated Version ----------");
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "new version:");
LOGGER.log(Level.WARNING, updater.getVersionUrl());
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "---------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
Metrics metrics = new Metrics(this, Constants.bstats_id);
metrics.addCustomChart(new SimplePie("data_type", () -> mode.storage));

View File

@ -1,6 +1,9 @@
package org.eptalist.bounge;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.p2vman.Identifier;
import io.github.p2vman.updater.Updater;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
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.Arrays;
import java.util.List;
import java.util.logging.Logger;
import java.util.Map;
import java.util.stream.Collectors;
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() {
super("eptalist");
super(Boungecord.config.get().command.getPath());
}
@Override
@ -109,6 +112,16 @@ public class WhiteListCommand extends Command implements TabExecutor {
sender.sendMessage(new TextComponent("Failed to reload the configuration."));
}
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:
sender.sendMessage(new TextComponent("Unknown command. Use /eptalist help for the list of commands."));

View File

@ -7,6 +7,7 @@ plugins {
import de.undercouch.gradle.tasks.download.Download
subprojects {
plugins.apply("java")
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

View File

@ -1 +1 @@
version = 1.5
version = 1.6

View File

@ -1,9 +1,11 @@
package org.eptalist.spigot;
import com.google.gson.JsonObject;
import io.github.p2vman.lang.Lang;
import io.github.p2vman.profiling.ExempleProfiler;
import io.github.p2vman.profiling.Profiler;
import io.github.p2vman.updater.Updater;
import org.bukkit.ChatColor;
import org.eptalist.Config;
import io.github.p2vman.Identifier;
import org.eptalist.Constants;
@ -37,6 +39,13 @@ public final class EptaList extends JavaPlugin {
profiler.push("load");
config.load();
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) {
identifiers.add(mode1.id);
}
@ -57,22 +66,6 @@ public final class EptaList extends JavaPlugin {
@Override
public void onEnable() {
try {
Updater updater = Updater.getInstance();
JsonObject obj = updater.getLasted();
if (!getDescription().getVersion().equals(obj.get("name").getAsString())) {
LOGGER.log(Level.WARNING, "---------- Outdated Version ----------");
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "new version:");
LOGGER.log(Level.WARNING, updater.getVersionUrl());
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "---------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
profiler.push("init");
metrics = new Metrics(this, Constants.bstats_id);
@ -83,14 +76,31 @@ public final class EptaList extends JavaPlugin {
config = new Config.ConfigContainer(new File(data, "wh.json"));
load();
if (config.get().auto_update_check) {
try {
Updater updater = Updater.getInstance();
JsonObject obj = updater.getLasted();
if (!getDescription().getVersion().equals(obj.get("name").getAsString())) {
LOGGER.log(Level.WARNING, "---------- Outdated Version ----------");
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "new version:");
LOGGER.log(Level.WARNING, updater.getVersionUrl());
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "---------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
try {
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
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) {
e.printStackTrace();
}
@ -98,6 +108,7 @@ public final class EptaList extends JavaPlugin {
getServer().getPluginManager().registerEvents(new Event(), this);
metrics.addCustomChart(new SimplePie("data_type", () -> mode.storage));
LOGGER.log(Level.INFO, String.format("Init Plugin %sms", profiler.getElapsedTimeAndRemove(profiler.pop())));
System.out.println(Lang.LANG);
}
@Override

View File

@ -1,6 +1,10 @@
package org.eptalist.spigot;
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.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -27,7 +31,8 @@ public class WhiteListCommand extends Command {
"help",
"mode",
"kick_nolisted",
"reload"
"reload",
"info"
};
private final Permission permission_enable;
private final Permission permission_add;
@ -38,8 +43,8 @@ public class WhiteListCommand extends Command {
private final Permission permission_list;
public WhiteListCommand() {
super("eptalist");
public WhiteListCommand(Identifier identifier) {
super(identifier.getPath());
Function<Permission, Permission> recal = (p) -> {
p.recalculatePermissibles();
return p;
@ -64,13 +69,13 @@ public class WhiteListCommand extends Command {
case "off": if (testPermission(sender, permission_enable)) {
EptaList.config.get().enable = false;
EptaList.config.save();
sender.sendMessage("Whitelist disabled.");
sender.sendMessage(Lang.LANG.format("command.off"));
}
break;
case "on": if (testPermission(sender, permission_enable)) {
EptaList.config.get().enable = true;
EptaList.config.save();
sender.sendMessage("Whitelist enabled.");
sender.sendMessage(Lang.LANG.format("command.on"));
}
break;
case "add": if (testPermission(sender, permission_add)) {
@ -78,7 +83,7 @@ public class WhiteListCommand extends Command {
if (!Utils.len(args, 1)) {
sender.sendMessage("Usage: /" + commandLabel + " add <username>");
} 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 {
for (String line : info) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
@ -91,7 +96,7 @@ public class WhiteListCommand extends Command {
if (!Utils.len(args, 1)) {
sender.sendMessage("Usage: /" + commandLabel + " remove <username>");
} 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 {
for (String line : info) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line));
@ -112,9 +117,9 @@ public class WhiteListCommand extends Command {
EptaList.config.get().curent = id;
EptaList.config.save();
EptaList.load();
sender.sendMessage("Mode set to: " + id);
sender.sendMessage(Lang.LANG.format("command.mode.succes", id));
} 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)) {
try {
EptaList.load();
sender.sendMessage("Configuration reloaded successfully.");
sender.sendMessage(Lang.LANG.format("command.reload.succes"));
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage("Failed to reload the configuration.");
sender.sendMessage(Lang.LANG.format("command.reload.failed"));
}
}
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;
}
@ -232,7 +247,7 @@ public class WhiteListCommand extends Command {
if (target.hasPermission(permission.getName())) {
return true;
} else {
target.sendMessage(ChatColor.RED + "You don't have permission to perform this command.");
target.sendMessage(Lang.LANG.format("perm.throw"));
return false;
}
}

View File

@ -68,20 +68,6 @@ public class Velocity {
@Inject
public Velocity(ProxyServer server, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
try {
Updater updater = Updater.getInstance();
JsonObject obj = updater.getLasted();
if (!BuildConstants.VERSION.equals(obj.get("name").getAsString())) {
LOGGER.log(Level.WARNING, "---------- Outdated Version ----------");
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "new version:");
LOGGER.log(Level.WARNING, updater.getVersionUrl());
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "---------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
profiler.push("init");
this.metricsFactory = metricsFactory;
this.dataDirectory = dataDirectory;
@ -90,8 +76,24 @@ public class Velocity {
}
config = new Config.ConfigContainer(new File(dataDirectory.toFile(), "config.json"));
load();
if (config.get().auto_update_check) {
try {
Updater updater = Updater.getInstance();
JsonObject obj = updater.getLasted();
if (!BuildConstants.VERSION.equals(obj.get("name").getAsString())) {
LOGGER.log(Level.WARNING, "---------- Outdated Version ----------");
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "new version:");
LOGGER.log(Level.WARNING, updater.getVersionUrl());
LOGGER.log(Level.WARNING, "");
LOGGER.log(Level.WARNING, "---------------------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
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())));
}