Progress but no progress?
This commit is contained in:
+13
-18
@@ -3,23 +3,18 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Galaxy
|
||||
compileOnly("com.alttd:galaxy-api:1.17.1-R0.1-SNAPSHOT")
|
||||
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") // Minimessage
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||
}
|
||||
|
||||
//publishing {
|
||||
// publications {
|
||||
// create<MavenPublication>("mavenJava") {
|
||||
// from(components["java"])
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// repositories{
|
||||
// maven {
|
||||
// name = "maven"
|
||||
// url = uri("http://leo:8081/")
|
||||
// isAllowInsecureProtocol = true
|
||||
// credentials(PasswordCredentials::class)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
publishing {
|
||||
repositories{
|
||||
maven {
|
||||
name = "maven"
|
||||
url = uri("https://repo.destro.xyz/snapshots")
|
||||
credentials(PasswordCredentials::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -1,4 +1,4 @@
|
||||
package com.alttd.boosters.api;
|
||||
package com.alttd.boosterapi;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -35,4 +35,8 @@ public interface Booster {
|
||||
void stopBooster();
|
||||
|
||||
void saveBooster();
|
||||
|
||||
void finish();
|
||||
|
||||
boolean finished();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.alttd.boosterapi;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
|
||||
public interface BoosterAPI {
|
||||
|
||||
static BoosterAPI get() {
|
||||
return BoosterImplementation.get();
|
||||
}
|
||||
|
||||
LuckPerms getLuckPerms();
|
||||
|
||||
void reloadConfig();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alttd.boosterapi;
|
||||
|
||||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.boosterapi.database.Database;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
|
||||
public class BoosterImplementation implements BoosterAPI {
|
||||
|
||||
private static BoosterAPI instance;
|
||||
|
||||
private LuckPerms luckPerms;
|
||||
private Database database;
|
||||
|
||||
public BoosterImplementation() {
|
||||
instance = this;
|
||||
reloadConfig();
|
||||
|
||||
luckPerms = getLuckPerms();
|
||||
}
|
||||
|
||||
public static BoosterAPI get() {
|
||||
if (instance == null)
|
||||
instance = new BoosterImplementation();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPerms getLuckPerms() {
|
||||
if(luckPerms == null)
|
||||
luckPerms = LuckPermsProvider.get();
|
||||
return luckPerms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
Config.init();
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package com.alttd.boosters.api;
|
||||
package com.alttd.boosterapi;
|
||||
|
||||
public enum BoosterType {
|
||||
|
||||
@@ -6,6 +6,7 @@ public enum BoosterType {
|
||||
* MCMMO - implies all mcmmo skills are boosted
|
||||
*/
|
||||
MCMMO("mcmmo"),
|
||||
// TODO : add individual mcmmo skills
|
||||
/**
|
||||
* MYPET - Boosts MyPet exp gains
|
||||
*/
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package com.alttd.boosterapi.config;
|
||||
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Config {
|
||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||
private static final String HEADER = "";
|
||||
|
||||
private static File CONFIG_FILE;
|
||||
public static ConfigurationNode config;
|
||||
public static YamlConfigurationLoader configLoader;
|
||||
|
||||
static int version;
|
||||
static boolean verbose;
|
||||
|
||||
public static File CONFIGPATH;
|
||||
public static void init() {
|
||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "Boosters");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||
configLoader = YamlConfigurationLoader.builder()
|
||||
.file(CONFIG_FILE)
|
||||
.nodeStyle(NodeStyle.BLOCK)
|
||||
.build();
|
||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!CONFIG_FILE.exists()) {
|
||||
try {
|
||||
if(!CONFIG_FILE.createNewFile()) {
|
||||
return;
|
||||
}
|
||||
} catch (IOException error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
verbose = getBoolean("verbose", true);
|
||||
version = getInt("config-version", 1);
|
||||
|
||||
readConfig(Config.class, null);
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||
ALogger.fatal("Error reading config", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
ALogger.fatal("Error saving config", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static Object[] splitPath(String key) {
|
||||
return PATH_PATTERN.split(key);
|
||||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
if(config.node(splitPath(path)).virtual()) {
|
||||
try {
|
||||
config.node(splitPath(path)).set(def);
|
||||
} catch (SerializationException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if(config.node(splitPath(path)).virtual())
|
||||
config.node(splitPath(path)).set(TypeToken.get(String.class), def);
|
||||
} catch(SerializationException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean def) {
|
||||
set(path, def);
|
||||
return config.node(splitPath(path)).getBoolean(def);
|
||||
}
|
||||
|
||||
private static double getDouble(String path, double def) {
|
||||
set(path, def);
|
||||
return config.node(splitPath(path)).getDouble(def);
|
||||
}
|
||||
|
||||
private static int getInt(String path, int def) {
|
||||
set(path, def);
|
||||
return config.node(splitPath(path)).getInt(def);
|
||||
}
|
||||
|
||||
private static String getString(String path, String def) {
|
||||
setString(path, def);
|
||||
return config.node(splitPath(path)).getString(def);
|
||||
}
|
||||
|
||||
private static Long getLong(String path, Long def) {
|
||||
set(path, def);
|
||||
return config.node(splitPath(path)).getLong(def);
|
||||
}
|
||||
|
||||
private static <T> List<String> getList(String path, T def) {
|
||||
try {
|
||||
set(path, def);
|
||||
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
|
||||
} catch(SerializationException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
||||
public static String driver = "com.mysql.cj.jdbc.Driver";
|
||||
public static String host = "13.11.1.78";
|
||||
public static String port = "3306";
|
||||
public static String database = "McTestSql";
|
||||
public static String user = "root";
|
||||
public static String password = "foobar";
|
||||
public static String options = "?MaxPooledStatements=250&useSSL=false&autoReconnect=true&maxReconnects=3";
|
||||
private static void databaseSettings() {
|
||||
String path = "database.";
|
||||
driver = getString(path + "driver", driver);
|
||||
host = getString(path + "host", host);
|
||||
port = getString(path + "port", port);
|
||||
database = getString(path + "database", database);
|
||||
user = getString(path + "user", user);
|
||||
password = getString(path + "password", password);
|
||||
options = getString(path + "options", options);
|
||||
}
|
||||
|
||||
public static Long activeTaskCheckFrequency = 1L;
|
||||
public static Long taskCheckFrequency = 1L;
|
||||
private static void boosterTaskSettings() {
|
||||
activeTaskCheckFrequency = getLong("task.queue-frequency", activeTaskCheckFrequency);
|
||||
taskCheckFrequency = getLong("task.check-frequency", taskCheckFrequency);
|
||||
}
|
||||
|
||||
public static String pluginMessageChannel = "altitude:boosterplugin";
|
||||
private static void pluginMessageSettings() {
|
||||
pluginMessageChannel = getString("settings.message-channel", pluginMessageChannel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.alttd.boosterapi.config;
|
||||
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class ServerConfig {
|
||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||
|
||||
private final String serverName;
|
||||
private final String configPath;
|
||||
private final String defaultPath;
|
||||
|
||||
public ServerConfig(String serverName) {
|
||||
this.serverName = serverName;
|
||||
this.configPath = "server-settings." + this.serverName + ".";
|
||||
this.defaultPath = "server-settings.default.";
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Config.readConfig(ServerConfig.class, this);
|
||||
Config.saveConfig();
|
||||
}
|
||||
|
||||
public static Object[] splitPath(String key) {
|
||||
return PATH_PATTERN.split(key);
|
||||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
if(Config.config.node(splitPath(path)).virtual()) {
|
||||
try {
|
||||
Config.config.node(splitPath(path)).set(def);
|
||||
} catch (SerializationException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if(Config.config.node(splitPath(path)).virtual())
|
||||
Config.config.node(splitPath(path)).set(TypeToken.get(String.class), def);
|
||||
} catch(SerializationException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, boolean def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.node(splitPath(configPath+path)).getBoolean(
|
||||
Config.config.node(splitPath(defaultPath +path)).getBoolean(def));
|
||||
}
|
||||
|
||||
private double getDouble(String path, double def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.node(splitPath(configPath+path)).getDouble(
|
||||
Config.config.node(splitPath(defaultPath +path)).getDouble(def));
|
||||
}
|
||||
|
||||
private int getInt(String path, int def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.node(splitPath(configPath+path)).getInt(
|
||||
Config.config.node(splitPath(defaultPath +path)).getInt(def));
|
||||
}
|
||||
|
||||
private String getString(String path, String def) {
|
||||
set(defaultPath +path, def);
|
||||
return Config.config.node(splitPath(configPath+path)).getString(
|
||||
Config.config.node(splitPath(defaultPath +path)).getString(def));
|
||||
}
|
||||
|
||||
/** DO NOT EDIT ANYTHING ABOVE **/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alttd.boosterapi.database;
|
||||
|
||||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Database {
|
||||
|
||||
private static Connection connection;
|
||||
|
||||
public static Connection getConnection() {
|
||||
if (connection == null) {
|
||||
try {
|
||||
Class.forName(Config.driver);
|
||||
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + Config.host + ":" + Config.port + "/" + Config.database + Config.options, Config.user, Config.password);
|
||||
} catch (ClassNotFoundException | SQLException ex) {
|
||||
ALogger.fatal("Failed to connect to sql.", ex);
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
|
||||
connection = null;
|
||||
|
||||
} catch (SQLException ex) {
|
||||
ALogger.fatal("Failed to disconnect from sql.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.alttd.boosterapi.util;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
public class ALogger {
|
||||
|
||||
private static org.slf4j.Logger logger;
|
||||
|
||||
public static void init(org.slf4j.Logger log) {
|
||||
logger = log;
|
||||
}
|
||||
|
||||
private void log(String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
public static void warn(String message) {
|
||||
logger.warn(message);
|
||||
}
|
||||
|
||||
public static void info(String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
logger.error(message);
|
||||
}
|
||||
|
||||
public static void fatal(String error, Exception exception) {
|
||||
logger.error(error + "\n" + ExceptionUtils.getStackTrace(exception));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.alttd.boosterapi.util;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static Component parseMiniMessage(String message, List<Template> templates) {
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
if (templates == null) {
|
||||
return miniMessage.deserialize(message);
|
||||
} else {
|
||||
return miniMessage.deserialize(message, TemplateResolver.templates(templates));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.alttd.boosters.api;
|
||||
|
||||
public interface BoosterAPI {
|
||||
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.alttd.boosters.api;
|
||||
|
||||
public class BoosterManager {
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user