add toml config

add Language.java
move package to io.github.p2vman.eptalist
and minor changes
This commit is contained in:
p2vman 2025-03-28 20:24:05 +02:00
parent 8830ba91c6
commit 8410e05bc2
42 changed files with 272 additions and 97 deletions

View File

@ -14,12 +14,12 @@ repositories {
} }
dependencies { dependencies {
implementation "com.google.code.gson:gson:2.8.9" compileOnly "com.google.code.gson:gson:2.8.9"
annotationProcessor 'org.projectlombok:lombok:1.18.30' annotationProcessor 'org.projectlombok:lombok:1.18.30'
compileOnly 'org.projectlombok:lombok:1.18.30' compileOnly 'org.projectlombok:lombok:1.18.30'
compileOnly("com.moandjiezana.toml:toml4j:0.7.2")
} }
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
} }

View File

@ -1,5 +1,8 @@
package io.github.p2vman; package io.github.p2vman;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Map; import java.util.Map;
public class Utils { public class Utils {
@ -7,6 +10,21 @@ public class Utils {
return t.length > l; return t.length > l;
} }
public static <K, V> MapWappeler<K, V> wappeler(Map<K, V> map) {
return new MapWappeler<>(map);
}
@Getter
@AllArgsConstructor
public static class MapWappeler<K, V> {
public final Map<K, V> map;
public MapWappeler<K, V> put(K k, V v) {
map.put(k, v);
return this;
}
}
public static <K, V> Map<K, V> put(Map<K, V> map, K k, V v) { public static <K, V> Map<K, V> put(Map<K, V> map, K k, V v) {
map.put(k, v); map.put(k, v);
return map; return map;

View File

@ -1,11 +1,15 @@
package org.eptalist; package io.github.p2vman.eptalist;
import com.google.gson.annotations.SerializedName; 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.Identifier;
import io.github.p2vman.Static; import io.github.p2vman.Static;
import io.github.p2vman.Utils; import io.github.p2vman.Utils;
import java.io.*; import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -56,8 +60,10 @@ public class Config {
public static class ConfigContainer { public static class ConfigContainer {
private File config; private File config;
private Config cfg = null; private Config cfg = null;
private boolean json;
public ConfigContainer(File config) { public ConfigContainer(File config) {
this.config = config; this.config = config;
this.json = config.getName().endsWith(".json");
} }
public Config get() { public Config get() {
@ -72,12 +78,21 @@ public class Config {
if (!config.exists()) { if (!config.exists()) {
this.cfg = new Config(); this.cfg = new Config();
try (FileWriter writer =new FileWriter(this.config, StandardCharsets.UTF_8)) { try (FileWriter writer =new FileWriter(this.config, StandardCharsets.UTF_8)) {
Static.GSON.toJson(cfg, writer); if (json) {
Static.GSON.toJson(cfg, writer);
}
else {
new TomlWriter().write(cfg, writer);
}
} }
} }
else { else {
try (FileReader reader = new FileReader(this.config, StandardCharsets.UTF_8)) { try (FileReader reader = new FileReader(this.config, StandardCharsets.UTF_8)) {
cfg = Static.GSON.fromJson(reader, Config.class); if (json) {
cfg = Static.GSON.fromJson(reader, Config.class);
} else {
cfg = new Toml().read(reader).to(Config.class);
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -87,7 +102,12 @@ public class Config {
public void save() { public void save() {
try (FileWriter writer = new FileWriter(this.config, StandardCharsets.UTF_8)) { try (FileWriter writer = new FileWriter(this.config, StandardCharsets.UTF_8)) {
Static.GSON.toJson(cfg, writer); if (json) {
Static.GSON.toJson(cfg, writer);
}
else {
new TomlWriter().write(cfg, writer);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -1,4 +1,4 @@
package org.eptalist; package io.github.p2vman.eptalist;
public class Constants { public class Constants {
public static final int bstats_id = 24527; public static final int bstats_id = 24527;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.metrics; package io.github.p2vman.eptalist.metrics;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -1,4 +1,4 @@
package org.eptalist.storge; package io.github.p2vman.eptalist.storge;
import java.io.Closeable; import java.io.Closeable;
import java.util.List; import java.util.List;
@ -11,4 +11,7 @@ public interface Data<T> extends Closeable {
boolean addUser(T name, List<String> info); boolean addUser(T name, List<String> info);
boolean removeUser(T name, List<String> info); boolean removeUser(T name, List<String> info);
boolean is(T name, List<String> info); boolean is(T name, List<String> info);
default boolean dirty() {
return false;
}
} }

View File

@ -1,4 +1,4 @@
package org.eptalist.storge; package io.github.p2vman.eptalist.storge;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;

View File

@ -1,4 +1,4 @@
package org.eptalist.storge; package io.github.p2vman.eptalist.storge;
import io.github.p2vman.lang.Lang; import io.github.p2vman.lang.Lang;

View File

@ -1,4 +1,4 @@
package org.eptalist.storge; package io.github.p2vman.eptalist.storge;
import io.github.p2vman.lang.Lang; import io.github.p2vman.lang.Lang;
import io.github.p2vman.nbt.NbtIo; import io.github.p2vman.nbt.NbtIo;

View File

@ -1,4 +1,4 @@
package org.eptalist.storge; package io.github.p2vman.eptalist.storge;
import io.github.p2vman.lang.Lang; import io.github.p2vman.lang.Lang;

View File

@ -0,0 +1,65 @@
package io.github.p2vman.eptalist.storge;
import io.github.p2vman.Utils;
import j.ApiStatus;
import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ApiStatus.In_Development
public abstract class Storge<T> implements Closeable {
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();
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) {
}
if (cls == null) throw new ClassNotFoundException();
if (!Data.class.isAssignableFrom(cls)) throw new ClassCastException();
return (Class<? extends Data<String>>) cls;
}
public boolean dirty() {
return false;
}
@Override
public void close() throws IOException {
}
public abstract List<T> toList();
public abstract Answer addUser(T name);
public abstract Answer removeUser(T name);
public abstract Answer is(T name);
@ApiStatus.In_Development
public class Answer {
}
}

View File

@ -86,7 +86,7 @@ public class Language implements Lang, BiConsumer<String, String>, Consumer<Inpu
return formatter.format(getOrDefult(id), args); return formatter.format(getOrDefult(id), args);
} }
public Formatter setFormatter(Formatter formatter) { public Formatter setFormater(Formatter formatter) {
this.formatter = formatter; this.formatter = formatter;
return formatter; return formatter;
} }

View File

@ -1,7 +1,7 @@
package io.github.p2vman.nbt.tag; package io.github.p2vman.nbt.tag;
import io.github.p2vman.nbt.TagWriter;
import io.github.p2vman.nbt.TagReader; import io.github.p2vman.nbt.TagReader;
import io.github.p2vman.nbt.TagWriter;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;

View File

@ -1,7 +1,7 @@
package io.github.p2vman.nbt.tag; package io.github.p2vman.nbt.tag;
import io.github.p2vman.nbt.TagWriter;
import io.github.p2vman.nbt.TagReader; import io.github.p2vman.nbt.TagReader;
import io.github.p2vman.nbt.TagWriter;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;

View File

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Stack; import java.util.Stack;
public class ExempleProfiler implements Profiler { public class ExempleProfiler implements Profiler {
private static final String $file = "https://github.com/p2vman/EptaListProject/blob/master/base/src/main/java/io/github/p2vman/profiling/ExempleProfiler.java";
private final Map<String, Long> totalTimes = new HashMap<>(); private final Map<String, Long> totalTimes = new HashMap<>();
private final Stack<String> stack = new Stack<>(); private final Stack<String> stack = new Stack<>();
private final Map<String, Long> startTimes = new HashMap<>(); private final Map<String, Long> startTimes = new HashMap<>();
@ -16,12 +17,13 @@ public class ExempleProfiler implements Profiler {
public String pop() { public String pop() {
if (stack.isEmpty()) { if (stack.isEmpty()) {
throw new IllegalStateException("Нет активных блоков для остановки."); throw new IllegalStateException($file+"#L20");
} }
String name = stack.pop(); String name = stack.pop();
Long startTime = startTimes.remove(name); Long startTime = startTimes.remove(name);
if (startTime == null) { if (startTime == null) {
throw new IllegalStateException("Блок " + name + " не был запущен."); System.out.println($file+"#L26");
throw new IllegalStateException(name);
} }
long elapsedTime = System.nanoTime() - startTime; long elapsedTime = System.nanoTime() - startTime;
totalTimes.put(name, totalTimes.getOrDefault(name, 0L) + elapsedTime); totalTimes.put(name, totalTimes.getOrDefault(name, 0L) + elapsedTime);
@ -30,7 +32,7 @@ public class ExempleProfiler implements Profiler {
public String peek() { public String peek() {
if (stack.isEmpty()) { if (stack.isEmpty()) {
throw new IllegalStateException("Нет активных блоков."); throw new IllegalStateException($file+"#L35");
} }
return stack.peek(); return stack.peek();
} }
@ -38,7 +40,8 @@ public class ExempleProfiler implements Profiler {
public long getElapsedTimeAndRemove(String name) { public long getElapsedTimeAndRemove(String name) {
Long elapsedTime = totalTimes.remove(name); Long elapsedTime = totalTimes.remove(name);
if (elapsedTime == null) { if (elapsedTime == null) {
throw new IllegalStateException("Блок " + name + " не найден."); System.out.println($file+"#L44");
throw new IllegalStateException(name);
} }
return elapsedTime / 1_000_000; return elapsedTime / 1_000_000;
} }
@ -46,7 +49,8 @@ public class ExempleProfiler implements Profiler {
public long getElapsedTime(String name) { public long getElapsedTime(String name) {
Long elapsedTime = totalTimes.get(name); Long elapsedTime = totalTimes.get(name);
if (elapsedTime == null) { if (elapsedTime == null) {
throw new IllegalStateException("Блок " + name + " не найден."); System.out.println($file+"#L53");
throw new IllegalStateException(name);
} }
return elapsedTime / 1_000_000; return elapsedTime / 1_000_000;
} }

View File

@ -0,0 +1,7 @@
package j;
public class ApiStatus {
public @interface In_Development {
}
}

View File

@ -26,6 +26,7 @@
"succes": "Mode set to: %s", "succes": "Mode set to: %s",
"invalid.id": "&4Invalid mode ID!" "invalid.id": "&4Invalid mode ID!"
}, },
"default": "Unknown command. Use /eptalist help for the list of commands.",
"on": "Whitelist enabled.", "on": "Whitelist enabled.",
"off": "Whitelist disabled." "off": "Whitelist disabled."
}, },

View File

@ -1,16 +1,17 @@
package org.eptalist.bounge; package io.github.p2vman.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.eptalist.storge.Storge;
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 net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import org.eptalist.Config; import io.github.p2vman.eptalist.Config;
import org.eptalist.Constants; import io.github.p2vman.eptalist.Constants;
import org.eptalist.bounge.metrics.Metrics; import io.github.p2vman.eptalist.bounge.metrics.Metrics;
import org.eptalist.metrics.SimplePie; import io.github.p2vman.eptalist.metrics.SimplePie;
import org.eptalist.storge.Data; import io.github.p2vman.eptalist.storge.Data;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -41,7 +42,7 @@ public final class Boungecord extends Plugin {
} }
} }
try { try {
list = (Data) Class.forName(mode.storage).getConstructor(Map.class).newInstance(mode.data); list = (Data) Storge.find(mode.storage).getConstructor(Map.class).newInstance(mode.data);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -54,7 +55,10 @@ public final class Boungecord extends Plugin {
if (!data.exists()) { if (!data.exists()) {
data.mkdirs(); data.mkdirs();
} }
config = new Config.ConfigContainer(new File(data, "wh.json")); File cf = new File(data, "wh.json");
if (!cf.exists()) cf = new File(data, "config.toml");
config = new Config.ConfigContainer(cf);
load(); load();
if (config.get().auto_update_check) if (config.get().auto_update_check)
{ {

View File

@ -1,4 +1,4 @@
package org.eptalist.bounge; package io.github.p2vman.eptalist.bounge;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.PendingConnection;

View File

@ -1,8 +1,9 @@
package org.eptalist.bounge; package io.github.p2vman.eptalist.bounge;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.github.p2vman.Identifier; import io.github.p2vman.Identifier;
import io.github.p2vman.lang.Lang;
import io.github.p2vman.updater.Updater; 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;
@ -33,13 +34,13 @@ public class WhiteListCommand extends Command implements TabExecutor {
case "off": case "off":
Boungecord.config.get().enable = false; Boungecord.config.get().enable = false;
Boungecord.config.save(); Boungecord.config.save();
sender.sendMessage(new TextComponent("Whitelist disabled.")); sender.sendMessage(new TextComponent(Lang.LANG.format("command.off")));
break; break;
case "on": case "on":
Boungecord.config.get().enable = true; Boungecord.config.get().enable = true;
Boungecord.config.save(); Boungecord.config.save();
sender.sendMessage(new TextComponent("Whitelist enabled.")); sender.sendMessage(new TextComponent(Lang.LANG.format("command.on")));
break; break;
case "add": case "add":
@ -50,7 +51,7 @@ public class WhiteListCommand extends Command implements TabExecutor {
String usernameToAdd = args[1]; String usernameToAdd = args[1];
List<String> infoAdd = new ArrayList<>(); List<String> infoAdd = new ArrayList<>();
if (Boungecord.list.addUser(usernameToAdd, infoAdd)) { if (Boungecord.list.addUser(usernameToAdd, infoAdd)) {
sender.sendMessage(new TextComponent("User added to the whitelist: " + usernameToAdd)); sender.sendMessage(new TextComponent(Lang.LANG.format("command.add.succes", usernameToAdd)));
} else { } else {
infoAdd.forEach(line -> sender.sendMessage(new TextComponent(line))); infoAdd.forEach(line -> sender.sendMessage(new TextComponent(line)));
} }
@ -64,7 +65,7 @@ public class WhiteListCommand extends Command implements TabExecutor {
String usernameToRemove = args[1]; String usernameToRemove = args[1];
List<String> infoRemove = new ArrayList<>(); List<String> infoRemove = new ArrayList<>();
if (Boungecord.list.removeUser(usernameToRemove, infoRemove)) { if (Boungecord.list.removeUser(usernameToRemove, infoRemove)) {
sender.sendMessage(new TextComponent("User removed from the whitelist: " + usernameToRemove)); sender.sendMessage(new TextComponent(Lang.LANG.format("command.remove.succes", usernameToRemove)));
} else { } else {
infoRemove.forEach(line -> sender.sendMessage(new TextComponent(line))); infoRemove.forEach(line -> sender.sendMessage(new TextComponent(line)));
} }
@ -84,9 +85,9 @@ public class WhiteListCommand extends Command implements TabExecutor {
Boungecord.config.get().curent = id; Boungecord.config.get().curent = id;
Boungecord.config.save(); Boungecord.config.save();
Boungecord.load(); Boungecord.load();
sender.sendMessage(new TextComponent("Mode set to: " + id)); sender.sendMessage(new TextComponent(Lang.LANG.format("command.mode.succes", id)));
} else { } else {
sender.sendMessage(new TextComponent("Invalid mode ID!")); sender.sendMessage(new TextComponent(Lang.LANG.format("command.mode.invalid.id")));
} }
break; break;
@ -106,10 +107,10 @@ public class WhiteListCommand extends Command implements TabExecutor {
case "reload": case "reload":
try { try {
Boungecord.load(); Boungecord.load();
sender.sendMessage(new TextComponent("Configuration reloaded successfully.")); sender.sendMessage(new TextComponent(Lang.LANG.format("command.reload.succes")));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
sender.sendMessage(new TextComponent("Failed to reload the configuration.")); sender.sendMessage(new TextComponent(Lang.LANG.format("command.reload.failed")));
} }
break; break;
case "info": case "info":
@ -124,7 +125,7 @@ public class WhiteListCommand extends Command implements TabExecutor {
} }
default: default:
sender.sendMessage(new TextComponent("Unknown command. Use /eptalist help for the list of commands.")); sender.sendMessage(new TextComponent(Lang.LANG.getOrDefult("command.default")));
break; break;
} }
} }

View File

@ -1,4 +1,4 @@
package org.eptalist.bounge.metrics; package io.github.p2vman.eptalist.bounge.metrics;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -27,8 +27,8 @@ import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration; import net.md_5.bungee.config.YamlConfiguration;
import org.eptalist.metrics.CustomChart; import io.github.p2vman.eptalist.metrics.CustomChart;
import org.eptalist.metrics.JsonObjectBuilder; import io.github.p2vman.eptalist.metrics.JsonObjectBuilder;
public class Metrics { public class Metrics {

View File

@ -1,5 +1,5 @@
name: EptaList name: EptaList
version: '${version}' version: '${version}'
main: org.eptalist.bounge.Boungecord main: io.github.p2vman.eptalist.bounge.Boungecord
authors: authors:
- p2vman - p2vman

View File

@ -2,6 +2,7 @@
plugins { plugins {
id 'java' id 'java'
id 'de.undercouch.download' version '5.4.0' apply false id 'de.undercouch.download' version '5.4.0' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1'
} }
import de.undercouch.gradle.tasks.download.Download import de.undercouch.gradle.tasks.download.Download
@ -31,6 +32,7 @@ ext {
} }
task mergePlugins(type: Jar) { task mergePlugins(type: Jar) {
dependsOn shadowJar
def io = it def io = it
archiveBaseName = 'EptaList' archiveBaseName = 'EptaList'
archiveVersion = version archiveVersion = version
@ -44,8 +46,10 @@ task mergePlugins(type: Jar) {
dependsOn task dependsOn task
jr.add(task.get().archiveFile.get()) jr.add(task.get().archiveFile.get())
} }
jr.add(file("./build/libs/libs-LOL.jar"))
return jr return jr
} }
from jars().collect { zipTree(it) } from jars().collect { zipTree(it) }
from(file("LICENSE")) { from(file("LICENSE")) {
@ -64,11 +68,24 @@ task mergePlugins(type: Jar) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE duplicatesStrategy = DuplicatesStrategy.INCLUDE
} }
tasks.build {
task mergeALL() {
dependsOn mergePlugins dependsOn mergePlugins
} }
dependencies {
implementation("com.moandjiezana.toml:toml4j:0.7.2")
}
shadowJar {
archiveBaseName.set('libs')
archiveClassifier.set('')
archiveVersion.set("LOL")
exclude 'com/google/gson/**'
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
}
tasks.register('downloadBungeeCord', Download) { tasks.register('downloadBungeeCord', Download) {
src 'https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar' src 'https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar'
dest file("$buildDir/downloads/BungeeCord.jar") dest file("$buildDir/downloads/BungeeCord.jar")

View File

@ -1,17 +1,18 @@
package org.eptalist.spigot; package io.github.p2vman.eptalist.spigot;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.github.p2vman.eptalist.spigot.metrics.Metrics;
import io.github.p2vman.eptalist.storge.Storge;
import io.github.p2vman.lang.Lang; 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.bukkit.ChatColor;
import org.eptalist.Config; import io.github.p2vman.eptalist.Config;
import io.github.p2vman.Identifier; import io.github.p2vman.Identifier;
import org.eptalist.Constants; import io.github.p2vman.eptalist.Constants;
import org.eptalist.metrics.SimplePie; import io.github.p2vman.eptalist.metrics.SimplePie;
import org.eptalist.spigot.metrics.Metrics; import io.github.p2vman.eptalist.storge.Data;
import org.eptalist.storge.Data;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandMap; import org.bukkit.command.CommandMap;
@ -57,7 +58,7 @@ public final class EptaList extends JavaPlugin {
} }
} }
try { try {
list = (Data) Class.forName(mode.storage).getConstructor(Map.class).newInstance(mode.data); list = (Data) Storge.find(mode.storage).getConstructor(Map.class).newInstance(mode.data);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -73,7 +74,11 @@ public final class EptaList extends JavaPlugin {
if (!data.exists()) { if (!data.exists()) {
data.mkdirs(); data.mkdirs();
} }
config = new Config.ConfigContainer(new File(data, "wh.json"));
File cf = new File(data, "wh.json");
if (!cf.exists()) cf = new File(data, "config.toml");
config = new Config.ConfigContainer(cf);
load(); load();
if (config.get().auto_update_check) { if (config.get().auto_update_check) {
@ -108,7 +113,6 @@ 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

View File

@ -1,4 +1,4 @@
package org.eptalist.spigot; package io.github.p2vman.eptalist.spigot;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -6,7 +6,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.eptalist.Config; import io.github.p2vman.eptalist.Config;
public class Event implements Listener { public class Event implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)

View File

@ -1,10 +1,11 @@
package org.eptalist.spigot; package io.github.p2vman.eptalist.spigot;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.github.p2vman.lang.Lang; import io.github.p2vman.lang.Lang;
import io.github.p2vman.updater.Updater; import io.github.p2vman.updater.Updater;
import net.md_5.bungee.api.chat.TextComponent;
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;
@ -166,12 +167,13 @@ public class WhiteListCommand extends Command {
sender.sendMessage(""); sender.sendMessage("");
break; break;
} }
default:
sender.sendMessage(Lang.LANG.getOrDefult("command.default"));
break;
} }
return true; return true;
} }
@Override @Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException { public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null"); Validate.notNull(sender, "Sender cannot be null");

View File

@ -1,11 +1,11 @@
package org.eptalist.spigot.metrics; package io.github.p2vman.eptalist.spigot.metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.eptalist.metrics.CustomChart; import io.github.p2vman.eptalist.metrics.CustomChart;
import org.eptalist.metrics.JsonObjectBuilder; import io.github.p2vman.eptalist.metrics.JsonObjectBuilder;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.io.*; import java.io.*;

View File

@ -1,5 +1,5 @@
name: EptaList name: EptaList
version: "${version}" version: "${version}"
main: org.eptalist.spigot.EptaList main: io.github.p2vman.eptalist.spigot.EptaList
authors: authors:
- p2vman - p2vman

View File

@ -0,0 +1,21 @@
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.

View File

@ -5,7 +5,7 @@ plugins {
} }
evaluationDependsOn(':base') evaluationDependsOn(':base')
group = 'org.eptalist' group = 'io.github.p2vman.eptalist.velocity'
version = project.findProperty("version") version = project.findProperty("version")
repositories { repositories {

View File

@ -1,25 +1,26 @@
package org.eptalist.velocity; package io.github.p2vman.eptalist.velocity;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.LoginEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import io.github.p2vman.Identifier; import io.github.p2vman.Identifier;
import io.github.p2vman.eptalist.Config;
import io.github.p2vman.eptalist.Constants;
import io.github.p2vman.eptalist.metrics.SimplePie;
import io.github.p2vman.eptalist.storge.Data;
import io.github.p2vman.eptalist.storge.Storge;
import io.github.p2vman.eptalist.velocity.metrics.Metrics;
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 net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.eptalist.Config;
import org.eptalist.Constants;
import org.eptalist.metrics.SimplePie;
import org.eptalist.storge.Data;
import org.eptalist.velocity.metrics.Metrics;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.File; import java.io.File;
@ -59,7 +60,7 @@ public class Velocity {
} }
} }
try { try {
list = (Data) Class.forName(mode.storage).getConstructor(Map.class).newInstance(mode.data); list = (Data) Storge.find(mode.storage).getConstructor(Map.class).newInstance(mode.data);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -74,7 +75,12 @@ public class Velocity {
if (!Files.exists(dataDirectory)) { if (!Files.exists(dataDirectory)) {
dataDirectory.toFile().mkdirs(); dataDirectory.toFile().mkdirs();
} }
config = new Config.ConfigContainer(new File(dataDirectory.toFile(), "config.json"));
File cf = new File(dataDirectory.toFile(), "config.json");
if (!cf.exists()) cf = new File(dataDirectory.toFile(), "config.toml");
config = new Config.ConfigContainer(cf);
load(); load();
if (config.get().auto_update_check) { if (config.get().auto_update_check) {
try { try {
@ -92,6 +98,7 @@ public class Velocity {
e.printStackTrace(); e.printStackTrace();
} }
} }
CommandManager commandManager = server.getCommandManager(); CommandManager commandManager = server.getCommandManager();
commandManager.register(config.get().command.getPath(), 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())));

View File

@ -1,9 +1,10 @@
package org.eptalist.velocity; package io.github.p2vman.eptalist.velocity;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import io.github.p2vman.Identifier; import io.github.p2vman.Identifier;
import io.github.p2vman.lang.Lang;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -44,13 +45,13 @@ public class WhiteListCommand implements SimpleCommand {
case "off": case "off":
Velocity.config.get().enable = false; Velocity.config.get().enable = false;
Velocity.config.save(); Velocity.config.save();
sender.sendMessage(Component.text("Whitelist disabled.")); sender.sendMessage(Component.text(Lang.LANG.format("command.off")));
break; break;
case "on": case "on":
Velocity.config.get().enable = true; Velocity.config.get().enable = true;
Velocity.config.save(); Velocity.config.save();
sender.sendMessage(Component.text("Whitelist enabled.")); sender.sendMessage(Component.text(Lang.LANG.format("command.on")));
break; break;
case "add": case "add":
@ -61,7 +62,7 @@ public class WhiteListCommand implements SimpleCommand {
String usernameToAdd = args[1]; String usernameToAdd = args[1];
List<String> infoAdd = new ArrayList<>(); List<String> infoAdd = new ArrayList<>();
if (Velocity.list.addUser(usernameToAdd, infoAdd)) { if (Velocity.list.addUser(usernameToAdd, infoAdd)) {
sender.sendMessage(Component.text("User added to the whitelist: " + usernameToAdd)); sender.sendMessage(Component.text(Lang.LANG.format("command.add.succes", usernameToAdd)));
} else { } else {
infoAdd.forEach(line -> sender.sendMessage(Component.text(line))); infoAdd.forEach(line -> sender.sendMessage(Component.text(line)));
} }
@ -75,7 +76,7 @@ public class WhiteListCommand implements SimpleCommand {
String usernameToRemove = args[1]; String usernameToRemove = args[1];
List<String> infoRemove = new ArrayList<>(); List<String> infoRemove = new ArrayList<>();
if (Velocity.list.removeUser(usernameToRemove, infoRemove)) { if (Velocity.list.removeUser(usernameToRemove, infoRemove)) {
sender.sendMessage(Component.text("User removed from the whitelist: " + usernameToRemove)); sender.sendMessage(Component.text(Lang.LANG.format("command.remove.succes", usernameToRemove)));
} else { } else {
infoRemove.forEach(line -> sender.sendMessage(Component.text(line))); infoRemove.forEach(line -> sender.sendMessage(Component.text(line)));
} }
@ -95,9 +96,9 @@ public class WhiteListCommand implements SimpleCommand {
Velocity.config.get().curent = id; Velocity.config.get().curent = id;
Velocity.config.save(); Velocity.config.save();
Velocity.load(); Velocity.load();
sender.sendMessage(Component.text("Mode set to: " + id)); sender.sendMessage(Component.text(Lang.LANG.format("command.mode.succes", id)));
} else { } else {
sender.sendMessage(Component.text("Invalid mode ID!")); sender.sendMessage(Component.text(Lang.LANG.format("command.mode.invalid.id")));
} }
break; break;
case "help": case "help":
@ -116,15 +117,15 @@ public class WhiteListCommand implements SimpleCommand {
case "reload": case "reload":
try { try {
Velocity.load(); Velocity.load();
sender.sendMessage(Component.text("Configuration reloaded successfully.")); sender.sendMessage(Component.text(Lang.LANG.format("command.reload.succes")));
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to reload the configuration.", e); logger.error("Failed to reload the configuration.", e);
sender.sendMessage(Component.text("Failed to reload the configuration.")); sender.sendMessage(Component.text(Lang.LANG.format("command.reload.failed")));
} }
break; break;
default: default:
sender.sendMessage(Component.text("Unknown command. Use /eptalist help for the list of commands.")); sender.sendMessage(Component.text(Lang.LANG.getOrDefult("command.default")));
break; break;
} }
} }

View File

@ -1,4 +1,4 @@
package org.eptalist.velocity.metrics; package io.github.p2vman.eptalist.velocity.metrics;
/* /*
* This Metrics class was auto-generated and can be copied into your project if you are * This Metrics class was auto-generated and can be copied into your project if you are
@ -20,8 +20,8 @@ import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription; import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import org.eptalist.metrics.CustomChart; import io.github.p2vman.eptalist.metrics.CustomChart;
import org.eptalist.metrics.JsonObjectBuilder; import io.github.p2vman.eptalist.metrics.JsonObjectBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;

View File

@ -1,4 +1,4 @@
package org.eptalist.velocity; package io.github.p2vman.eptalist.velocity;
// The constants are replaced before compilation // The constants are replaced before compilation
public class BuildConstants { public class BuildConstants {