Update velocity version
This commit is contained in:
parent
e8e3293416
commit
d7dadc6b6d
|
|
@ -38,8 +38,8 @@ dependencies {
|
||||||
// Minimessage
|
// Minimessage
|
||||||
// implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
// implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
||||||
// Velocity
|
// Velocity
|
||||||
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") // Velocity
|
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT") // Velocity
|
||||||
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||||
// JDA
|
// JDA
|
||||||
implementation("net.dv8tion:JDA:5.0.0-beta.2") {
|
implementation("net.dv8tion:JDA:5.0.0-beta.2") {
|
||||||
exclude("opus-java") // exclude audio
|
exclude("opus-java") // exclude audio
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,10 @@ import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
|
||||||
import com.alttd.proxydiscordlink.util.ALogger;
|
import com.alttd.proxydiscordlink.util.ALogger;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.ConfigurationOptions;
|
import org.spongepowered.configurate.ConfigurationOptions;
|
||||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -27,7 +26,7 @@ public class BotConfig {
|
||||||
|
|
||||||
private static File CONFIG_FILE;
|
private static File CONFIG_FILE;
|
||||||
public static ConfigurationNode config;
|
public static ConfigurationNode config;
|
||||||
public static YAMLConfigurationLoader configLoader;
|
public static YamlConfigurationLoader configLoader;
|
||||||
|
|
||||||
static int version;
|
static int version;
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
@ -38,9 +37,8 @@ public class BotConfig {
|
||||||
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "DiscordLink");
|
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "DiscordLink");
|
||||||
CONFIG_FILE = new File(CONFIGPATH, "bot-config.yml");
|
CONFIG_FILE = new File(CONFIGPATH, "bot-config.yml");
|
||||||
|
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YamlConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.file(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
|
||||||
.build();
|
.build();
|
||||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||||
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||||
|
|
@ -58,7 +56,7 @@ public class BotConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = configLoader.load(ConfigurationOptions.defaults().setHeader(HEADER));
|
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -81,24 +79,24 @@ public class BotConfig {
|
||||||
try {
|
try {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
throw Throwables.propagate(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException e) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
throw Throwables.propagate(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveConfig() {
|
public static void saveConfig() {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException e) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
throw Throwables.propagate(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,58 +105,64 @@ public class BotConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void set(String path, Object def) {
|
private static void set(String path, Object def) {
|
||||||
if (config.getNode(splitPath(path)).isVirtual())
|
if (config.node(splitPath(path)).virtual()) {
|
||||||
config.getNode(splitPath(path)).setValue(def);
|
try {
|
||||||
|
config.node(splitPath(path)).set(def);
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setString(String path, String def) {
|
private static void setString(String path, String def) {
|
||||||
try {
|
try {
|
||||||
if (config.getNode(splitPath(path)).isVirtual())
|
if (config.node(splitPath(path)).virtual())
|
||||||
config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
config.node(splitPath(path)).set(String.class, def);
|
||||||
} catch (ObjectMappingException ex) {
|
} catch (SerializationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getBoolean(String path, boolean def) {
|
private static boolean getBoolean(String path, boolean def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getBoolean(def);
|
return config.node(splitPath(path)).getBoolean(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getDouble(String path, double def) {
|
private static double getDouble(String path, double def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getDouble(def);
|
return config.node(splitPath(path)).getDouble(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getInt(String path, int def) {
|
private static int getInt(String path, int def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getInt(def);
|
return config.node(splitPath(path)).getInt(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getString(String path, String def) {
|
private static String getString(String path, String def) {
|
||||||
setString(path, def);
|
setString(path, def);
|
||||||
return config.getNode(splitPath(path)).getString(def);
|
return config.node(splitPath(path)).getString(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long getLong(String path, Long def) {
|
private static Long getLong(String path, Long def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getLong(def);
|
return config.node(splitPath(path)).getLong(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> List<String> getList(String path, T def) {
|
private static <T> List<String> getList(String path, T def) {
|
||||||
try {
|
try {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getList(TypeToken.of(String.class));
|
return config.node(splitPath(path)).getList(String.class);
|
||||||
} catch (ObjectMappingException ex) {
|
} catch (SerializationException e) {
|
||||||
}
|
}
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigurationNode getNode(String path) {
|
private static ConfigurationNode getNode(String path) {
|
||||||
if (config.getNode(splitPath(path)).isVirtual()) {
|
if (config.node(splitPath(path)).virtual()) {
|
||||||
//new RegexConfig("Dummy");
|
//new RegexConfig("Dummy");
|
||||||
}
|
}
|
||||||
config.getChildrenMap();
|
config.childrenMap();
|
||||||
return config.getNode(splitPath(path));
|
return config.node(splitPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -203,12 +207,12 @@ public class BotConfig {
|
||||||
private static void prefix() {
|
private static void prefix() {
|
||||||
prefixMap.clear();
|
prefixMap.clear();
|
||||||
ConfigurationNode node = getNode("prefixes");
|
ConfigurationNode node = getNode("prefixes");
|
||||||
if (node.getChildrenMap().isEmpty()) {
|
if (node.childrenMap().isEmpty()) {
|
||||||
ALogger.warn("No prefixes found in BotConfig, add them to use commands:\n" +
|
ALogger.warn("No prefixes found in BotConfig, add them to use commands:\n" +
|
||||||
"prefixes:\n\t" +
|
"prefixes:\n\t" +
|
||||||
"server_id: prefix");
|
"server_id: prefix");
|
||||||
}
|
}
|
||||||
node.getChildrenMap().forEach((key, value) -> {
|
node.childrenMap().forEach((key, value) -> {
|
||||||
prefixMap.put((Long) key, value.getString());
|
prefixMap.put((Long) key, value.getString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -216,7 +220,7 @@ public class BotConfig {
|
||||||
private static void roles() {
|
private static void roles() {
|
||||||
DiscordRole.cleanDiscordRoles();
|
DiscordRole.cleanDiscordRoles();
|
||||||
ConfigurationNode node = getNode("sync-roles");
|
ConfigurationNode node = getNode("sync-roles");
|
||||||
if (node.getChildrenMap().isEmpty())
|
if (node.childrenMap().isEmpty())
|
||||||
ALogger.warn("No roles found in BotConfig, add them to use sync-roles feature:\n" +
|
ALogger.warn("No roles found in BotConfig, add them to use sync-roles feature:\n" +
|
||||||
"sync-roles:\n\t" +
|
"sync-roles:\n\t" +
|
||||||
"example_rank:\n\t\t" +
|
"example_rank:\n\t\t" +
|
||||||
|
|
@ -226,14 +230,14 @@ public class BotConfig {
|
||||||
"update-to-minecraft: true\n\t\t" +
|
"update-to-minecraft: true\n\t\t" +
|
||||||
"update-to-discord: true\n\t\t" +
|
"update-to-discord: true\n\t\t" +
|
||||||
"announcement: <player> got example rank!");
|
"announcement: <player> got example rank!");
|
||||||
node.getChildrenMap().forEach((key, value) -> {
|
node.childrenMap().forEach((key, value) -> {
|
||||||
String internalName = key.toString();
|
String internalName = key.toString();
|
||||||
long id = value.getNode("role-id").getLong(-1);
|
long id = value.node("role-id").getLong(-1);
|
||||||
String luckpermsName = value.getNode("luckperms-name").getString("example");
|
String luckpermsName = value.node("luckperms-name").getString("example");
|
||||||
String display_name = value.getNode("display-name").getString("Example");
|
String display_name = value.node("display-name").getString("Example");
|
||||||
boolean updateToMinecraft = value.getNode("update-to-minecraft").getBoolean(false);
|
boolean updateToMinecraft = value.node("update-to-minecraft").getBoolean(false);
|
||||||
boolean updateToDiscord = value.getNode("update-to-discord").getBoolean(false);
|
boolean updateToDiscord = value.node("update-to-discord").getBoolean(false);
|
||||||
String announcement = value.getNode("announcement").getString("<player> got example rank!");
|
String announcement = value.node("announcement").getString("<player> got example rank!");
|
||||||
|
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
ALogger.error("Invalid id in BotConfig for roles.");
|
ALogger.error("Invalid id in BotConfig for roles.");
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@ package com.alttd.proxydiscordlink.config;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.ConfigurationOptions;
|
import org.spongepowered.configurate.ConfigurationOptions;
|
||||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
import org.aarboard.nextcloud.api.utils.WebdavInputStream;
|
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -24,7 +23,7 @@ public final class Config {
|
||||||
|
|
||||||
private static File CONFIG_FILE;
|
private static File CONFIG_FILE;
|
||||||
public static ConfigurationNode config;
|
public static ConfigurationNode config;
|
||||||
public static YAMLConfigurationLoader configLoader;
|
public static YamlConfigurationLoader configLoader;
|
||||||
|
|
||||||
static int version;
|
static int version;
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
@ -35,9 +34,8 @@ public final class Config {
|
||||||
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "DiscordLink");
|
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "DiscordLink");
|
||||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||||
|
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YamlConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.file(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
|
||||||
.build();
|
.build();
|
||||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||||
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||||
|
|
@ -55,7 +53,7 @@ public final class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = configLoader.load(ConfigurationOptions.defaults().setHeader(HEADER));
|
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -78,24 +76,24 @@ public final class Config {
|
||||||
try {
|
try {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
throw Throwables.propagate(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException e) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
throw Throwables.propagate(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveConfig() {
|
public static void saveConfig() {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException e) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
throw Throwables.propagate(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,58 +102,64 @@ public final class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void set(String path, Object def) {
|
private static void set(String path, Object def) {
|
||||||
if (config.getNode(splitPath(path)).isVirtual())
|
if (config.node(splitPath(path)).virtual()) {
|
||||||
config.getNode(splitPath(path)).setValue(def);
|
try {
|
||||||
|
config.node(splitPath(path)).set(def);
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setString(String path, String def) {
|
private static void setString(String path, String def) {
|
||||||
try {
|
try {
|
||||||
if (config.getNode(splitPath(path)).isVirtual())
|
if (config.node(splitPath(path)).virtual())
|
||||||
config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
config.node(splitPath(path)).set(String.class, def);
|
||||||
} catch (ObjectMappingException ex) {
|
} catch (SerializationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getBoolean(String path, boolean def) {
|
private static boolean getBoolean(String path, boolean def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getBoolean(def);
|
return config.node(splitPath(path)).getBoolean(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getDouble(String path, double def) {
|
private static double getDouble(String path, double def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getDouble(def);
|
return config.node(splitPath(path)).getDouble(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getInt(String path, int def) {
|
private static int getInt(String path, int def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getInt(def);
|
return config.node(splitPath(path)).getInt(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getString(String path, String def) {
|
private static String getString(String path, String def) {
|
||||||
setString(path, def);
|
setString(path, def);
|
||||||
return config.getNode(splitPath(path)).getString(def);
|
return config.node(splitPath(path)).getString(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long getLong(String path, Long def) {
|
private static Long getLong(String path, Long def) {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getLong(def);
|
return config.node(splitPath(path)).getLong(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> List<String> getList(String path, T def) {
|
private static <T> List<String> getList(String path, T def) {
|
||||||
try {
|
try {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.getNode(splitPath(path)).getList(TypeToken.of(String.class));
|
return config.node(splitPath(path)).getList(String.class);
|
||||||
} catch (ObjectMappingException ex) {
|
} catch (SerializationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigurationNode getNode(String path) {
|
private static ConfigurationNode getNode(String path) {
|
||||||
if (config.getNode(splitPath(path)).isVirtual()) {
|
if (config.node(splitPath(path)).virtual()) {
|
||||||
//new RegexConfig("Dummy");
|
//new RegexConfig("Dummy");
|
||||||
}
|
}
|
||||||
config.getChildrenMap();
|
config.childrenMap();
|
||||||
return config.getNode(splitPath(path));
|
return config.node(splitPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.alttd.proxydiscordlink.database;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class WordPressDatabase {
|
||||||
|
|
||||||
|
public Optional<Integer> getLastId() { //TODO use this to let players know if there was a new announcement
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = DatabaseConnection.getConnection().prepareStatement("SELECT MAX(id) FROM wp_posts");
|
||||||
|
ResultSet result = statement.executeQuery();
|
||||||
|
if (result.next()) {
|
||||||
|
return Optional.of(result.getInt(1));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.alttd.proxydiscordlink.database;
|
||||||
|
|
||||||
|
import com.alttd.proxydiscordlink.DiscordLink;
|
||||||
|
import com.alttd.proxydiscordlink.config.Config;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class WordPressDatabaseConnection {
|
||||||
|
|
||||||
|
private static WordPressDatabaseConnection instance;
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
|
public WordPressDatabaseConnection() throws SQLException {
|
||||||
|
instance = this;
|
||||||
|
instance.openConnection();
|
||||||
|
DiscordLink.getPlugin().getDatabase().createTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openConnection() throws SQLException {
|
||||||
|
if (this.connection == null || this.connection.isClosed()) {
|
||||||
|
synchronized(this) {
|
||||||
|
if (this.connection == null || this.connection.isClosed()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
this.connection = DriverManager.getConnection("jdbc:"
|
||||||
|
+ Config.WORDPRESS_DB.DRIVERS + "://"
|
||||||
|
+ Config.WORDPRESS_DB.IP + ":"
|
||||||
|
+ Config.WORDPRESS_DB.PORT + "/"
|
||||||
|
+ Config.WORDPRESS_DB.DATABASE_NAME
|
||||||
|
+ "?autoReconnect=true&useSSL=false", Config.WORDPRESS_DB.USERNAME,
|
||||||
|
Config.WORDPRESS_DB.PASSWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() {
|
||||||
|
try {
|
||||||
|
instance.openConnection();
|
||||||
|
} catch (SQLException var1) {
|
||||||
|
var1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance.connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initialize() throws SQLException {
|
||||||
|
instance = new WordPressDatabaseConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.alttd.proxydiscordlink.minecraft.listeners;
|
||||||
|
|
||||||
|
import com.alttd.proxydiscordlink.database.WordPressDatabase;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
//Sorry this is not really a listener...
|
||||||
|
public class AnnouncementListener {
|
||||||
|
|
||||||
|
int lastId;
|
||||||
|
|
||||||
|
private static AnnouncementListener instance;
|
||||||
|
|
||||||
|
public static AnnouncementListener getInstance() {
|
||||||
|
if (instance == null)
|
||||||
|
instance = new AnnouncementListener();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AnnouncementListener() {
|
||||||
|
lastId = checkLatestAnnouncement();
|
||||||
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
|
// Schedule the task to run every 5 minutes
|
||||||
|
executorService.scheduleAtFixedRate(() -> {
|
||||||
|
// Call the function you want to execute
|
||||||
|
lastId = checkLatestAnnouncement();
|
||||||
|
}, 5, 5, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int checkLatestAnnouncement() {
|
||||||
|
return new WordPressDatabase().getLastId().orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentId() {
|
||||||
|
return lastId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package com.alttd.proxydiscordlink.util;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public class EvidenceTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldReturnEvidenceUrl() {
|
|
||||||
Evidence evidence = new Evidence();
|
|
||||||
Optional<String> evidenceUrl = evidence.getNewEvidenceFolder("akastijn").join();
|
|
||||||
assertTrue(evidenceUrl.isPresent());
|
|
||||||
System.out.println(evidenceUrl.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user