Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import xyz.srnyx.gradlegalaxy.enums.Repository
import xyz.srnyx.gradlegalaxy.enums.repository
import xyz.srnyx.gradlegalaxy.utility.*

Expand All @@ -11,12 +12,14 @@ plugins {
paper("1.18.2")
setupAnnoyingAPI("0d3c33c14c", "gg.eventalerts", "1.0.0", "A plugin to integrate your Minecraft server with the Event Alerts ecosystem", JavaVersion.VERSION_21)

repository(Repository.SCARSZ)
repository("https://repo.triumphteam.dev/snapshots/")
dependencies {
implementationRelocate(project, "dev.triumphteam:triumph-gui-paper:4.0.0-SNAPSHOT", "dev.triumphteam")
compileOnly("org.java-websocket", "Java-WebSocket", "1.6.0")
compileOnly("org.mongodb", "bson", "5.3.0")
compileOnly("net.fellbaum", "jemoji", "1.7.1")
compileOnly("com.discordsrv", "discordsrv", "1.28.0")
}

val projectPackage = getPackage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import gg.eventalerts.eventalertsintegration.config.ConfigYml;
import gg.eventalerts.eventalertsintegration.socket.WebSockets;

import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.objects.managers.AccountLinkManager;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
Expand Down Expand Up @@ -34,9 +37,9 @@ public class EventAlertsIntegration extends AnnoyingPlugin {
.append(Component.text(" for more information", NamedTextColor.GRAY))
.build();


@NotNull public ConfigYml config;
public WebSockets webSockets;
@Nullable public AccountLinkManager accountLinkManager;

public EventAlertsIntegration() {
options
Expand All @@ -58,6 +61,8 @@ public void reload() {
// Reconnect websockets
if (webSockets == null) webSockets = new WebSockets(this);
webSockets.reconnectAll("Plugin reload");
// DiscordSRV
if (config.linking.discordSRV && Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) accountLinkManager = DiscordSRV.getPlugin().getAccountLinkManager();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import gg.eventalerts.eventalertsintegration.EventAlertsIntegration;
import gg.eventalerts.eventalertsintegration.socket.SocketEndpoint;

import github.scarsz.discordsrv.DiscordSRV;
import org.bson.types.ObjectId;

import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;

import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -49,10 +52,12 @@ public class Linking {
@NotNull public static final String PATH_REQUIRE_LINK = PATH_LINKING + ".require-link";
@NotNull public static final String PATH_CHECK_ON_JOIN = PATH_LINKING + ".check-on-join";
@NotNull public static final String PATH_ALLOW_JOIN_ON_FAILURE = PATH_LINKING + ".allow-join-on-failure";
@NotNull public static final String PATH_DISCORDSRV = PATH_LINKING + ".discordsrv";

public boolean requireLink = getBoolean(PATH_REQUIRE_LINK);
public boolean checkOnJoin = getBoolean(PATH_CHECK_ON_JOIN, true);
public boolean allowJoinOnFailure = getBoolean(PATH_ALLOW_JOIN_ON_FAILURE);
public boolean discordSRV = getBoolean(PATH_DISCORDSRV, true);

public void setRequireLink(boolean newStatus) {
if (requireLink == newStatus) return;
Expand All @@ -64,6 +69,18 @@ public void setRequireLink(boolean newStatus) {
// Reconnect websocket
eaPlugin.webSockets.reconnect("Config updated", SocketEndpoint.LINK);
}

public void setDiscordSRV(boolean newStatus) {
if (discordSRV == newStatus) return;

// Update config
discordSRV = newStatus;
setSave(PATH_DISCORDSRV, newStatus);

// Update accountLinkManager
final Plugin discordSRVPlugin = discordSRV ? Bukkit.getPluginManager().getPlugin("DiscordSRV") : null;
eaPlugin.accountLinkManager = discordSRVPlugin != null ? ((DiscordSRV) discordSRVPlugin).getAccountLinkManager() : null;
}
}

public class CrossBan {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public PaperGuiBuilder getGUI() {
playDingSound(newStatus);
open(false);
})))
.statelessComponent(container -> container.setItem(3,
ConfigMainGui.booleanItem(
plugin.config.linking.discordSRV,
"DiscordSRV integration",
"Whether to also link players with\nDiscordSRV when they link with Event Alerts",
(player, context) -> {
final boolean newStatus = !plugin.config.linking.discordSRV;
plugin.config.linking.setDiscordSRV(newStatus);
playDingSound(newStatus);
open(false);
}
)))
.statelessComponent(container -> container.setItem(4, backButton()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gg.eventalerts.eventalertsintegration.EventAlertsIntegration;
import gg.eventalerts.eventalertsintegration.objects.CrossBan;
import gg.eventalerts.eventalertsintegration.objects.EAObject;
import gg.eventalerts.eventalertsintegration.objects.EAPlayer;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -19,6 +20,7 @@
import xyz.srnyx.annoyingapi.AnnoyingListener;
import xyz.srnyx.annoyingapi.AnnoyingPlugin;
import xyz.srnyx.annoyingapi.libs.javautilities.HttpUtility;
import xyz.srnyx.annoyingapi.libs.javautilities.MiscUtility;

import java.util.UUID;
import java.util.logging.Level;
Expand Down Expand Up @@ -76,8 +78,19 @@ private boolean checkLinking(@NotNull PlayerLoginEvent event) {
return false;
}

// Player is linked
if (!playerElement.isJsonNull()) {
if (plugin.accountLinkManager != null) MiscUtility.handleException(() -> EAObject.newObject(plugin, EAPlayer.class, playerElement.getAsJsonObject()))
.filter(ea -> ea.discord != null)
.map(ea -> String.valueOf(ea.discord.id))
.ifPresent(discordId -> {
if (!discordId.equals(plugin.accountLinkManager.getDiscordId(uuid))) plugin.accountLinkManager.link(discordId, uuid);
});
return true;
}

// Disallow if not linked
if (!playerElement.isJsonNull()) return true;
if (plugin.accountLinkManager != null) plugin.accountLinkManager.unlink(uuid);
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, Component.text()
.append(EventAlertsIntegration.GATE)
.append(Component.text("You must link your Minecraft account with Event Alerts to join this server!\n\n", NamedTextColor.RED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ public LinkClient(@NotNull EventAlertsIntegration plugin) {

@Override
public boolean shouldConnect() {
return plugin.config.linking.requireLink;
return plugin.config.linking.requireLink || plugin.accountLinkManager != null;
}

@Override
public void handle(@NotNull EAPlayer eaPlayer) {
if (eaPlayer.minecraft == null) return;

// Linked
if (eaPlayer.linkStatus == EAPlayer.LinkStatus.ADDED && eaPlayer.discord != null) return;
if (eaPlayer.linkStatus == EAPlayer.LinkStatus.ADDED && eaPlayer.discord != null && plugin.accountLinkManager != null) {
// Link with DiscordSRV
plugin.accountLinkManager.link(String.valueOf(eaPlayer.discord.id), eaPlayer.minecraft.uuid);
return;
}

// Unlinked
if (eaPlayer.linkStatus == EAPlayer.LinkStatus.REMOVED && plugin.config.linking.requireLink) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ linking:
# Whether to allow players to join the server when the linking check fails
allow-join-on-failure: false

# Whether the plugin should link/unlink players with DiscordSRV automatically
# None of the other linking settings need to be enabled for this to work
discordsrv: true



# Settings related to Event Alerts' cross-banning feature
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ main: ${mainPackage}.${name}
version: ${version}
api-version: 1.18.2

softdepend:
- DiscordSRV

commands:
eventalerts:
description: Primary command for Event Alerts
Expand Down