Compare commits
6 Commits
next_cloud
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7dadc6b6d | ||
|
|
e8e3293416 | ||
|
|
34b8824d49 | ||
|
|
8ddbfcd521 | ||
|
|
7083235d68 | ||
|
|
baf88ed43e |
5
Jenkinsfile
vendored
5
Jenkinsfile
vendored
|
|
@ -1,9 +1,12 @@
|
|||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
NEXUS_CREDS = credentials('alttd-snapshot-user')
|
||||
}
|
||||
stages {
|
||||
stage('Gradle') {
|
||||
steps {
|
||||
sh 'bash gradlew shadowJar -x test'
|
||||
sh './gradlew shadowJar -x test -PalttdSnapshotUsername=$NEXUS_CREDS_USR -PalttdSnapshotPassword=$NEXUS_CREDS_PSW'
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ plugins {
|
|||
allprojects {
|
||||
group = "com.alttd.proxydiscordlink"
|
||||
description = "A velocity plugin to link Discord and Minecraft accounts."
|
||||
version = "1.0.1-SNAPSHOT"
|
||||
|
||||
apply(plugin = "java")
|
||||
apply(plugin = "maven-publish")
|
||||
|
|
@ -37,21 +38,20 @@ dependencies {
|
|||
// Minimessage
|
||||
// implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
||||
// Velocity
|
||||
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") // Velocity
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
|
||||
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT") // Velocity
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
// JDA
|
||||
implementation("net.dv8tion:JDA:5.0.0-beta.2") {
|
||||
shadow("net.dv8tion:JDA:5.0.0-beta.2") {
|
||||
exclude("opus-java") // exclude audio
|
||||
}
|
||||
|
||||
compileOnly("com.gitlab.ruany:LitebansAPI:0.3.5")
|
||||
// LuckPerms
|
||||
compileOnly("net.luckperms:api:5.3")
|
||||
// MySQL
|
||||
runtimeOnly("mysql:mysql-connector-java:8.0.23")
|
||||
// ShutdownInfo
|
||||
compileOnly("com.alttd:ShutdownInfo:1.0")
|
||||
}
|
||||
compileOnly("com.alttd:shutdowninfo:1.0.0-SNAPSHOT")
|
||||
|
||||
implementation("org.aarboard.nextcloud:nextcloud-api:13.1.0") //NextCloud
|
||||
|
||||
|
|
@ -80,15 +80,20 @@ dependencies {
|
|||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
artifact(tasks.shadowJar.get()) {
|
||||
classifier = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories{
|
||||
maven {
|
||||
name = "maven"
|
||||
url = uri("https://repo.destro.xyz/snapshots")
|
||||
credentials(PasswordCredentials::class)
|
||||
name = "nexus"
|
||||
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
|
||||
credentials {
|
||||
username = project.property("alttdSnapshotUsername") as String
|
||||
password = project.property("alttdSnapshotPassword") as String
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,19 @@
|
|||
rootProject.name = "ProxyDiscordLink"
|
||||
|
||||
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").get()
|
||||
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").get()
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
// Altitude
|
||||
maven {
|
||||
name = "maven"
|
||||
url = uri("https://repo.destro.xyz/snapshots")
|
||||
credentials(PasswordCredentials::class)
|
||||
name = "nexus"
|
||||
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
|
||||
credentials {
|
||||
username = nexusUser
|
||||
password = nexusPass
|
||||
}
|
||||
}
|
||||
// Velocity
|
||||
maven("https://nexus.velocitypowered.com/repository/maven-public/")
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ public class DiscordLink {
|
|||
private Bot bot;
|
||||
|
||||
@Inject
|
||||
public DiscordLink(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory)
|
||||
{
|
||||
public DiscordLink(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
|
||||
plugin = this;
|
||||
server = proxyServer;
|
||||
logger = proxyLogger;
|
||||
|
|
@ -71,6 +70,12 @@ public class DiscordLink {
|
|||
loadEvents();
|
||||
loadBot();
|
||||
new LiteBansBanListener().registerEvents();
|
||||
// try {
|
||||
// WordPressDatabaseConnection.initialize();
|
||||
// ALogger.error("*** Could not connect to the wordpress database. ***");
|
||||
// } catch (SQLException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
|
|
@ -94,7 +99,6 @@ public class DiscordLink {
|
|||
bot.connect();
|
||||
}
|
||||
|
||||
|
||||
public File getDataDirectory() {
|
||||
return dataDirectory.toFile();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.proxydiscordlink;
|
||||
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.CommandManager;
|
||||
import com.alttd.proxydiscordlink.util.ALogger;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.session.ReadyEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
|
@ -16,8 +17,9 @@ public class JDAListener extends ListenerAdapter {
|
|||
|
||||
@Override
|
||||
public void onReady(@NotNull ReadyEvent event) {
|
||||
CommandManager commandManager = new CommandManager(jda);
|
||||
jda.addEventListener(commandManager);
|
||||
// ALogger.info("JDA ready, loading command manager");
|
||||
// CommandManager commandManager = new CommandManager(jda);
|
||||
// jda.addEventListener(commandManager);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package com.alttd.proxydiscordlink.bot;
|
||||
|
||||
import com.alttd.proxydiscordlink.JDAListener;
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.CommandManager;
|
||||
import com.alttd.proxydiscordlink.bot.listeners.DiscordJoinListener;
|
||||
import com.alttd.proxydiscordlink.bot.listeners.DiscordRoleListener;
|
||||
import com.alttd.proxydiscordlink.bot.tasks.CheckLinkSync;
|
||||
import com.alttd.proxydiscordlink.config.BotConfig;
|
||||
|
|
@ -16,7 +17,6 @@ import net.dv8tion.jda.api.entities.Role;
|
|||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
||||
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -31,6 +31,7 @@ public class Bot {
|
|||
public void connect() {
|
||||
disconnect();
|
||||
try {
|
||||
ALogger.info("Creating bot instance");
|
||||
jda = JDABuilder
|
||||
.createDefault(BotConfig.DISCORD.BOT_TOKEN)
|
||||
.setMemberCachePolicy(MemberCachePolicy.ALL)
|
||||
|
|
@ -38,13 +39,17 @@ public class Bot {
|
|||
.build();
|
||||
jda.setAutoReconnect(true);
|
||||
jda.awaitReady();
|
||||
ALogger.info("JDA ready");
|
||||
jda.addEventListener(
|
||||
new DiscordRoleListener(),
|
||||
new JDAListener(jda));
|
||||
new DiscordJoinListener(),
|
||||
new DiscordRoleListener()/*,
|
||||
new JDAListener(jda)*/);
|
||||
DiscordLink.getPlugin().getProxy().getScheduler().buildTask(DiscordLink.getPlugin(), new CheckLinkSync())
|
||||
.delay(120, TimeUnit.SECONDS)
|
||||
.repeat(12, TimeUnit.HOURS)
|
||||
.schedule();
|
||||
CommandManager commandManager = new CommandManager(jda);
|
||||
jda.addEventListener(commandManager);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public class CommandManager extends ListenerAdapter {
|
|||
.filter(discordCommand -> discordCommand.getName().equalsIgnoreCase(commandName))
|
||||
.findFirst();
|
||||
if (first.isEmpty()) {
|
||||
ALogger.info(String.format("The command %s was used, but it's not on this plugin", commandName));
|
||||
return;
|
||||
}
|
||||
first.get().execute(event);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import net.dv8tion.jda.api.JDA;
|
|||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
|
@ -53,6 +54,7 @@ public class CommandLink extends DiscordCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
event.deferReply(true).queue(interactionHook -> {
|
||||
List<DiscordRole> discordRoles = Utilities.getDiscordRolesForUser(uuid, member);
|
||||
|
||||
DiscordLinkPlayer discordLinkPlayer = new DiscordLinkPlayer(
|
||||
|
|
@ -66,10 +68,11 @@ public class CommandLink extends DiscordCommand {
|
|||
.map(DiscordRole::getInternalName)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
linkAccount(discordLinkPlayer, event);
|
||||
linkAccount(discordLinkPlayer, event, interactionHook);
|
||||
});
|
||||
}
|
||||
|
||||
private void linkAccount(DiscordLinkPlayer discordLinkPlayer, SlashCommandInteractionEvent event) {
|
||||
private void linkAccount(DiscordLinkPlayer discordLinkPlayer, SlashCommandInteractionEvent event, InteractionHook interactionHook) {
|
||||
discordLinkPlayer.updateDiscord(
|
||||
DiscordRole.getDiscordRoles().stream()
|
||||
.filter(role -> discordLinkPlayer.getRoles().contains(role.getInternalName()))
|
||||
|
|
@ -87,27 +90,27 @@ public class CommandLink extends DiscordCommand {
|
|||
Guild guild = event.getGuild();
|
||||
Member member = event.getMember();
|
||||
if (guild == null || member == null) {
|
||||
Utilities.commandErrAutoRem("Unable to find guild", event);
|
||||
Utilities.commandErrAutoRem("Unable to find guild", interactionHook);
|
||||
return;
|
||||
}
|
||||
if (player != null || user != null)
|
||||
if (player != null || user != null) {
|
||||
DiscordLink.getPlugin().getBot().changeNick(
|
||||
guild.getIdLong(),
|
||||
member.getIdLong(),
|
||||
player == null ?
|
||||
user.getUsername() :
|
||||
player.getUsername());
|
||||
else
|
||||
} else {
|
||||
DiscordLink.getPlugin().getBot().changeNick(
|
||||
guild.getIdLong(),
|
||||
member.getIdLong(),
|
||||
discordLinkPlayer.getUsername());
|
||||
}
|
||||
|
||||
event.replyEmbeds(Utilities.genericSuccessEmbed("Success","You have successfully linked " +
|
||||
interactionHook.editOriginalEmbeds(Utilities.genericSuccessEmbed("Success","You have successfully linked " +
|
||||
discordLinkPlayer.getUsername() + " with " +
|
||||
discordLinkPlayer.getDiscordUsername() + "!"))
|
||||
.setEphemeral(true)
|
||||
.queue(result -> result.deleteOriginal().queueAfter(5, TimeUnit.SECONDS));
|
||||
.queue(result -> result.delete().queueAfter(5, TimeUnit.SECONDS));
|
||||
|
||||
DiscordLinkPlayer.addDiscordLinkPlayer(discordLinkPlayer);
|
||||
DiscordLink.getPlugin().getDatabase().syncPlayer(discordLinkPlayer);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.alttd.proxydiscordlink.bot.listeners;
|
||||
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
|
||||
import com.alttd.proxydiscordlink.database.Database;
|
||||
import com.alttd.proxydiscordlink.objects.DiscordLinkPlayer;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DiscordJoinListener extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
|
||||
User user = event.getUser();
|
||||
Database database = DiscordLink.getPlugin().getDatabase();
|
||||
if (database.playerIsLinked(user.getIdLong())) {
|
||||
DiscordLinkPlayer discordLinkPlayer = database.getPlayer(user.getIdLong());
|
||||
discordLinkPlayer.linkedRole(true);
|
||||
discordLinkPlayer.updateDiscord(
|
||||
DiscordRole.getDiscordRoles().stream()
|
||||
.filter(role -> discordLinkPlayer.getRoles().contains(role.getInternalName()))
|
||||
.collect(Collectors.toList()),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ public class CheckLinkSync implements Runnable {
|
|||
HashSet<Long> notInDbIds = membersIdSet.stream().filter(id -> !dbIdSet.contains(id)).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
fixNotInDb(members, notInDbIds);
|
||||
fixNoLinkRole(members, noRoleIds);
|
||||
// fixNoLinkRole(members, noRoleIds); //TODO remove this and find another way to do this cus this only finds cached members which most ppl aren't
|
||||
}
|
||||
|
||||
private void fixNotInDb(List<Member> members, Set<Long> notInDbIds) {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
|
|||
import com.alttd.proxydiscordlink.util.ALogger;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.ConfigurationOptions;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -27,7 +26,7 @@ public class BotConfig {
|
|||
|
||||
private static File CONFIG_FILE;
|
||||
public static ConfigurationNode config;
|
||||
public static YAMLConfigurationLoader configLoader;
|
||||
public static YamlConfigurationLoader configLoader;
|
||||
|
||||
static int version;
|
||||
static boolean verbose;
|
||||
|
|
@ -38,9 +37,8 @@ public class BotConfig {
|
|||
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "DiscordLink");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "bot-config.yml");
|
||||
|
||||
configLoader = YAMLConfigurationLoader.builder()
|
||||
.setFile(CONFIG_FILE)
|
||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||
configLoader = YamlConfigurationLoader.builder()
|
||||
.file(CONFIG_FILE)
|
||||
.build();
|
||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||
|
|
@ -58,7 +56,7 @@ public class BotConfig {
|
|||
}
|
||||
|
||||
try {
|
||||
config = configLoader.load(ConfigurationOptions.defaults().setHeader(HEADER));
|
||||
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -81,24 +79,24 @@ public class BotConfig {
|
|||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (IOException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (IOException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,58 +105,64 @@ public class BotConfig {
|
|||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
if (config.getNode(splitPath(path)).isVirtual())
|
||||
config.getNode(splitPath(path)).setValue(def);
|
||||
if (config.node(splitPath(path)).virtual()) {
|
||||
try {
|
||||
config.node(splitPath(path)).set(def);
|
||||
} catch (SerializationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if (config.getNode(splitPath(path)).isVirtual())
|
||||
config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
||||
} catch (ObjectMappingException ex) {
|
||||
if (config.node(splitPath(path)).virtual())
|
||||
config.node(splitPath(path)).set(String.class, def);
|
||||
} catch (SerializationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean 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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getList(TypeToken.of(String.class));
|
||||
} catch (ObjectMappingException ex) {
|
||||
return config.node(splitPath(path)).getList(String.class);
|
||||
} catch (SerializationException e) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private static ConfigurationNode getNode(String path) {
|
||||
if (config.getNode(splitPath(path)).isVirtual()) {
|
||||
if (config.node(splitPath(path)).virtual()) {
|
||||
//new RegexConfig("Dummy");
|
||||
}
|
||||
config.getChildrenMap();
|
||||
return config.getNode(splitPath(path));
|
||||
config.childrenMap();
|
||||
return config.node(splitPath(path));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -203,12 +207,12 @@ public class BotConfig {
|
|||
private static void prefix() {
|
||||
prefixMap.clear();
|
||||
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" +
|
||||
"prefixes:\n\t" +
|
||||
"server_id: prefix");
|
||||
}
|
||||
node.getChildrenMap().forEach((key, value) -> {
|
||||
node.childrenMap().forEach((key, value) -> {
|
||||
prefixMap.put((Long) key, value.getString());
|
||||
});
|
||||
}
|
||||
|
|
@ -216,7 +220,7 @@ public class BotConfig {
|
|||
private static void roles() {
|
||||
DiscordRole.cleanDiscordRoles();
|
||||
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" +
|
||||
"sync-roles:\n\t" +
|
||||
"example_rank:\n\t\t" +
|
||||
|
|
@ -226,14 +230,14 @@ public class BotConfig {
|
|||
"update-to-minecraft: true\n\t\t" +
|
||||
"update-to-discord: true\n\t\t" +
|
||||
"announcement: <player> got example rank!");
|
||||
node.getChildrenMap().forEach((key, value) -> {
|
||||
node.childrenMap().forEach((key, value) -> {
|
||||
String internalName = key.toString();
|
||||
long id = value.getNode("role-id").getLong(-1);
|
||||
String luckpermsName = value.getNode("luckperms-name").getString("example");
|
||||
String display_name = value.getNode("display-name").getString("Example");
|
||||
boolean updateToMinecraft = value.getNode("update-to-minecraft").getBoolean(false);
|
||||
boolean updateToDiscord = value.getNode("update-to-discord").getBoolean(false);
|
||||
String announcement = value.getNode("announcement").getString("<player> got example rank!");
|
||||
long id = value.node("role-id").getLong(-1);
|
||||
String luckpermsName = value.node("luckperms-name").getString("example");
|
||||
String display_name = value.node("display-name").getString("Example");
|
||||
boolean updateToMinecraft = value.node("update-to-minecraft").getBoolean(false);
|
||||
boolean updateToDiscord = value.node("update-to-discord").getBoolean(false);
|
||||
String announcement = value.node("announcement").getString("<player> got example rank!");
|
||||
|
||||
if (id == -1)
|
||||
ALogger.error("Invalid id in BotConfig for roles.");
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package com.alttd.proxydiscordlink.config;
|
|||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.ConfigurationOptions;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -23,7 +23,7 @@ public final class Config {
|
|||
|
||||
private static File CONFIG_FILE;
|
||||
public static ConfigurationNode config;
|
||||
public static YAMLConfigurationLoader configLoader;
|
||||
public static YamlConfigurationLoader configLoader;
|
||||
|
||||
static int version;
|
||||
static boolean verbose;
|
||||
|
|
@ -34,9 +34,8 @@ public final class Config {
|
|||
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "DiscordLink");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||
|
||||
configLoader = YAMLConfigurationLoader.builder()
|
||||
.setFile(CONFIG_FILE)
|
||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||
configLoader = YamlConfigurationLoader.builder()
|
||||
.file(CONFIG_FILE)
|
||||
.build();
|
||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||
|
|
@ -54,7 +53,7 @@ public final class Config {
|
|||
}
|
||||
|
||||
try {
|
||||
config = configLoader.load(ConfigurationOptions.defaults().setHeader(HEADER));
|
||||
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -77,24 +76,24 @@ public final class Config {
|
|||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (IOException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (IOException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,58 +102,64 @@ public final class Config {
|
|||
}
|
||||
|
||||
private static void set(String path, Object def) {
|
||||
if (config.getNode(splitPath(path)).isVirtual())
|
||||
config.getNode(splitPath(path)).setValue(def);
|
||||
if (config.node(splitPath(path)).virtual()) {
|
||||
try {
|
||||
config.node(splitPath(path)).set(def);
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if (config.getNode(splitPath(path)).isVirtual())
|
||||
config.getNode(splitPath(path)).setValue(TypeToken.of(String.class), def);
|
||||
} catch (ObjectMappingException ex) {
|
||||
if (config.node(splitPath(path)).virtual())
|
||||
config.node(splitPath(path)).set(String.class, def);
|
||||
} catch (SerializationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean 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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
set(path, def);
|
||||
return config.getNode(splitPath(path)).getList(TypeToken.of(String.class));
|
||||
} catch (ObjectMappingException ex) {
|
||||
return config.node(splitPath(path)).getList(String.class);
|
||||
} catch (SerializationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private static ConfigurationNode getNode(String path) {
|
||||
if (config.getNode(splitPath(path)).isVirtual()) {
|
||||
if (config.node(splitPath(path)).virtual()) {
|
||||
//new RegexConfig("Dummy");
|
||||
}
|
||||
config.getChildrenMap();
|
||||
return config.getNode(splitPath(path));
|
||||
config.childrenMap();
|
||||
return config.node(splitPath(path));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -174,7 +179,9 @@ public final class Config {
|
|||
@SuppressWarnings("unused")
|
||||
private static void loadSubclasses() {
|
||||
DB.database();
|
||||
WORDPRESS_DB.database();
|
||||
MESSAGES.loadMessages();
|
||||
NEXT_CLOUD.loadNextCloud();
|
||||
}
|
||||
|
||||
public static class DB {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.alttd.proxydiscordlink.minecraft.listeners;
|
|||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.config.BotConfig;
|
||||
import com.alttd.proxydiscordlink.objects.DiscordLinkPlayer;
|
||||
import com.alttd.proxydiscordlink.util.ALogger;
|
||||
import com.alttd.proxydiscordlink.util.Evidence;
|
||||
import com.alttd.proxydiscordlink.util.Utilities;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
|
@ -37,11 +38,16 @@ public class LiteBansBanListener {
|
|||
}
|
||||
|
||||
private void onBan(Entry entry) {
|
||||
if (entry == null)
|
||||
ALogger.info("Ban detected, making evidence...");
|
||||
if (entry == null) {
|
||||
ALogger.warn("Failed to find ban entry, no evidence made");
|
||||
return;
|
||||
}
|
||||
String stringUuid = entry.getUuid();
|
||||
if (stringUuid == null)
|
||||
if (stringUuid == null) {
|
||||
ALogger.warn("Failed to find uuid in entry, no evidence made");
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(stringUuid);
|
||||
|
||||
Optional<Player> player = DiscordLink.getPlugin().getProxy().getPlayer(uuid);
|
||||
|
|
@ -58,8 +64,14 @@ public class LiteBansBanListener {
|
|||
}
|
||||
}
|
||||
|
||||
ALogger.info(String.format("Making evidence folder for %s", username));
|
||||
|
||||
Evidence evidence = new Evidence();
|
||||
evidence.getNewEvidenceFolder(username).thenAcceptAsync(optionalUrl -> {
|
||||
evidence.getNewEvidenceFolder(username).handle((optionalUrl, ex) -> {
|
||||
if (ex != null) {
|
||||
ALogger.error("Failed to make evidence folder", ex);
|
||||
return Optional.empty();
|
||||
}
|
||||
Optional<MessageEmbed.Field> field = banDiscordUserIfExists(entry, uuid);
|
||||
|
||||
EmbedBuilder banEvidence = new EmbedBuilder()
|
||||
|
|
@ -68,17 +80,22 @@ public class LiteBansBanListener {
|
|||
.addField("Banned by", entry.getExecutorName() == null ? "unknown" : entry.getExecutorName(), true)
|
||||
.addField("Ban duration", getBanDuration(entry), true)
|
||||
.addField("Reason", entry.getReason() == null ? "unknown" : entry.getReason(), true)
|
||||
.setTitle("Auto Discord ban");
|
||||
.setTitle("Evidence");
|
||||
|
||||
Optional<String> returnUrl;
|
||||
if (optionalUrl.isPresent()) {
|
||||
banEvidence.addField("Evidence", optionalUrl.get(), false);
|
||||
String s = optionalUrl.get();
|
||||
banEvidence.addField("Evidence", s, false);
|
||||
returnUrl = Optional.of(s);
|
||||
} else {
|
||||
banEvidence.addField("Evidence", "Failed to get url, please make the folder yourself and reply to this post with the link.", false);
|
||||
returnUrl = Optional.empty();
|
||||
}
|
||||
|
||||
field.ifPresent(banEvidence::addField);
|
||||
|
||||
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(BotConfig.DISCORD.EVIDENCE_CHANNEL_ID, banEvidence, -1);
|
||||
return returnUrl;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import net.dv8tion.jda.api.entities.Member;
|
|||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
|
@ -218,6 +219,11 @@ public class Utilities {
|
|||
.queue(res -> res.deleteOriginal().queueAfter(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
public static void commandErrAutoRem(String text, InteractionHook event) {
|
||||
event.editOriginalEmbeds(Utilities.genericErrorEmbed("Error", text))
|
||||
.queue(res -> res.delete().queueAfter(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
|
||||
public static boolean removeRole(UUID uuid, String group) {
|
||||
User user = getLuckPerms().getUserManager().getUser(uuid);
|
||||
|
|
|
|||
|
|
@ -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