Skip to content
Merged
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
18 changes: 14 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id("xyz.srnyx.gradle-galaxy") version "2.1.0"
id("com.gradleup.shadow") version "8.3.9"
id("net.kyori.blossom") version "2.2.0"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.3"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.4.1"
}

paper(DependencyConfig(version = "1.18.2"))
Expand All @@ -20,12 +20,12 @@ setupAnnoyingAPI(
version = "1.1.0",
description = "A plugin to integrate your Minecraft server with the Event Alerts ecosystem",
javaVersion = JavaVersion.VERSION_21),
annoyingAPIConfig = DependencyConfig(version = "5.2.0"))
annoyingAPIConfig = DependencyConfig(version = "db46b2b"))

// Runtime dependency versions
val javaWebSocketVersion: String = "1.6.0"
val bsonVersion: String = "5.6.3"
val jEmojiVersion: String = "1.7.5"
val bsonVersion: String = "5.7.0"
val jEmojiVersion: String = "2.0.0"

// Blossom (see java-templates module)
sourceSets.main { blossom.javaSources {
Expand All @@ -51,6 +51,12 @@ dependencies {
}

compileOnly("me.clip:placeholderapi:2.12.2")

testImplementation("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
testImplementation("org.mongodb:bson:$bsonVersion")
testImplementation(platform("org.junit:junit-bom:6.1.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

// Unknown relocations
Expand All @@ -60,3 +66,7 @@ relocate("com.google.errorprone", "$projectPackage.libs.google.errorprone")
relocate("com.google.thirdparty", "$projectPackage.libs.google.thirdparty")
relocate("javax.annotation")
relocate("com.google.j2objc.annotations")

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gg.eventalerts.eventalertsintegration;

import org.jetbrains.annotations.NotNull;

import xyz.srnyx.annoyingapi.AnnoyingPlugin;
import xyz.srnyx.annoyingapi.library.AnnoyingLibrary;
import xyz.srnyx.annoyingapi.libs.libby.Library;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,24 @@

import gg.eventalerts.eventalertsintegration.config.ConfigYml;
import gg.eventalerts.eventalertsintegration.socket.WebSockets;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;

import org.bukkit.Bukkit;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import xyz.srnyx.annoyingapi.AnnoyingPlugin;
import xyz.srnyx.annoyingapi.PluginPlatform;
import xyz.srnyx.annoyingapi.libs.javautilities.MapGenerator;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;


public class EventAlertsIntegration extends AnnoyingPlugin {
@NotNull public static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
@NotNull public static final Map<Long, String> ID_MAPPINGS = MapGenerator.HASH_MAP.mapOf(
List.of(314853603695394817L, 365630764244664320L, 242385234992037888L, 604377897662414854L, 267734235224211467L, 381890968971902976L, 468890330763231270L, 1111741660892762142L, 1006349851241480242L, 1216096556713906288L, 1280002787446493256L, 1096205843113967669L, 533985117589471233L),
List.of("Skeppy", "Oiiink", "srnyx", "hailey", "bacca", "Rame", "hayech", "Server Events", "Famous Events", "Potential Skeppy Events", "Skeppy Sighting", "Random Pings", "Reece"));
@NotNull public static final TextComponent GATE = Component.text("EVENT ALERTS GATE\n\n", NamedTextColor.GOLD, TextDecoration.BOLD);
@NotNull public static final TextComponent LINKING_INSTRUCTIONS = Component.text()
.color(NamedTextColor.GRAY)
Expand All @@ -57,6 +46,8 @@ public EventAlertsIntegration() {
.registrationOptions.automaticRegistration.packages(
"gg.eventalerts.eventalertsintegration.commands",
"gg.eventalerts.eventalertsintegration.listeners");

libraryManager.loadLibrary(EALibrary.BSON);
}

@Override
Expand Down Expand Up @@ -105,14 +96,4 @@ public Map<String, String> getSocketHeaders() {
public void runOnMainThread(@NotNull Runnable runnable) {
Bukkit.getScheduler().runTask(this, runnable);
}

@Nullable
public static <T extends Enum<T>> T getEnum(@NotNull Class<T> enumClass, @Nullable String string) {
if (string != null) try {
return Enum.valueOf(enumClass, string.toUpperCase());
} catch (final IllegalArgumentException e) {
log(Level.WARNING, "Invalid " + enumClass.getSimpleName() + ": " + string);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gg.eventalerts.eventalertsintegration;

import org.jetbrains.annotations.NotNull;
import xyz.srnyx.annoyingapi.libs.javautilities.MapGenerator;

import java.util.List;
import java.util.Map;


public class IDMappings {
@NotNull public static final Map<Long, String> ID_MAPPINGS = MapGenerator.HASH_MAP.mapOf(List.of(
// Users
242385234992037888L, "srnyx",
365630764244664320L, "Oiiink",
381890968971902976L, "Rame",
533985117589471233L, "Reece",
267734235224211467L, "bacca",
604377897662414854L, "hailey",
314853603695394817L, "Skeppy",
468890330763231270L, "hayech",

// Roles
1406379715471610029L, "MC Server Pings",
1111741660892762142L, "Official Events",
1006349851241480242L, "Creator Events",
1426711659740790915L, "Event-B Info",
1216096556713906288L, "Potential Skeppy Events",
1280002787446493256L, "Skeppy Sighting",
1096205843113967669L, "Random Pings",
970434201990070424L, "Partner Events",
1498450271825825874L, "Big Money Events",
970434305203511359L, "Money Events",
970434303391576164L, "Fun Events",
970434294893928498L, "Housing Events",
1134932175821734119L, "Civilization Events",
980950599946362900L, "Community Events"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import gg.eventalerts.eventalertsintegration.EventAlertsIntegration;
import gg.eventalerts.eventalertsintegration.gui.config.ConfigGui;
import gg.eventalerts.eventalertsintegration.json.GSONProvider;
import gg.eventalerts.eventalertsintegration.objects.CrossBan;
import gg.eventalerts.eventalertsintegration.objects.EAObject;
import gg.eventalerts.eventalertsintegration.reflection.org.bukkit.entity.RefPlayer;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import org.jetbrains.annotations.NotNull;

import xyz.srnyx.annoyingapi.command.AnnoyingCommand;
import xyz.srnyx.annoyingapi.command.AnnoyingSender;
import xyz.srnyx.annoyingapi.libs.javautilities.HttpUtility;
Expand All @@ -29,7 +24,11 @@
import xyz.srnyx.annoyingapi.utility.BukkitUtility;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -283,8 +282,8 @@ public void onCommand(@NotNull AnnoyingSender sender) {
for (final JsonElement jsonElement : crossBans) {
final JsonObject jsonObject = MiscUtility.handleException(jsonElement::getAsJsonObject).orElse(null);
if (jsonObject == null) continue;
final CrossBan ban = EAObject.newObject(plugin, CrossBan.class, jsonObject);
if (ban == null) continue;
final CrossBan ban = GSONProvider.GSON.fromJson(jsonObject, CrossBan.class);
if (ban == null || ban.minecraftUuid == null) continue;
final Player player = Bukkit.getPlayer(ban.minecraftUuid);
if (player == null) continue;
banned++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

import gg.eventalerts.eventalertsintegration.EventAlertsIntegration;
import gg.eventalerts.eventalertsintegration.socket.SocketEndpoint;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import xyz.srnyx.annoyingapi.AnnoyingPlugin;
import xyz.srnyx.annoyingapi.file.AnnoyingResource;
import xyz.srnyx.annoyingapi.file.PlayableSound;
import xyz.srnyx.annoyingapi.libs.javautilities.HttpUtility;
import xyz.srnyx.annoyingapi.libs.javautilities.manipulation.Mapper;

import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;


public class ConfigYml extends AnnoyingResource {
@NotNull public static final String PATH_API_KEYS = "api-keys";
@NotNull public static final String PATH_DISCORD_MESSAGE_SYNCING = "discord-message-syncing";
@NotNull public static final String PATH_SYNCING = "syncing";
@NotNull public static final String PATH_LINKING = "linking";
@NotNull public static final String PATH_CROSS_BAN = "cross-ban";
@NotNull public static final String PATH_EVENT_MESSAGES = "event-messages";
Expand All @@ -27,7 +29,7 @@ public class ConfigYml extends AnnoyingResource {
@NotNull private final EventAlertsIntegration eaPlugin;

@NotNull public final ApiKeys apiKeys;
@NotNull public final DiscordMessageSyncing discordMessageSyncing;
@NotNull public final ConfigYml.Syncing syncing;
@NotNull public final Linking linking;
@NotNull public final CrossBan crossBan;
@NotNull public final EventMessages eventMessages;
Expand All @@ -38,7 +40,7 @@ public ConfigYml(@NotNull EventAlertsIntegration plugin) {
eaPlugin = plugin;

apiKeys = new ApiKeys();
discordMessageSyncing = new DiscordMessageSyncing();
syncing = new Syncing();
linking = new Linking();
crossBan = new CrossBan();
eventMessages = new EventMessages();
Expand Down Expand Up @@ -75,14 +77,60 @@ public ApiKeys() {
}
}

public class DiscordMessageSyncing {
@NotNull public static final String PATH_ENABLED = PATH_DISCORD_MESSAGE_SYNCING + ".enabled";
@NotNull public static final String DISCORDSRV_INTEGRATION = PATH_DISCORD_MESSAGE_SYNCING + ".discordsrv-integration";
@NotNull public static final String PATH_FORMAT = PATH_DISCORD_MESSAGE_SYNCING + ".format";
public class Syncing {
@NotNull public static final String PATH_DISCORD_TO_MINECRAFT = PATH_SYNCING + ".discord-to-minecraft";
@NotNull public static final String PATH_MINECRAFT_TO_DISCORD = PATH_SYNCING + ".minecraft-to-discord";

public boolean enabled = getBoolean(PATH_ENABLED, true);
public boolean discordSRVIntegration = getBoolean(DISCORDSRV_INTEGRATION, true);
@NotNull public String format = getString(PATH_FORMAT, "<dark_aqua>\uD83C\uDF89 [<event_title>] <aqua>[<author_name>] <content_stripped>");
@NotNull public final DiscordToMinecraft discordToMinecraft = new DiscordToMinecraft();
@NotNull public final MinecraftToDiscord minecraftToDiscord = new MinecraftToDiscord();

public class DiscordToMinecraft {
@NotNull public static final String PATH_MESSAGES = PATH_DISCORD_TO_MINECRAFT + ".messages";

@NotNull public final Messages messages = new Messages();

public class Messages {
@NotNull public static final String PATH_ENABLED = PATH_MESSAGES + ".enabled";
@NotNull public static final String PATH_FORMAT = PATH_MESSAGES + ".format";

public boolean enabled = getBoolean(PATH_ENABLED, true);
@NotNull public String format = getString(PATH_FORMAT, "<dark_aqua>\uD83C\uDF89 [<event_title>] <aqua>[<author_name>] <message_content_stripped><message_attachments_pretty>");

public void setEnabled(boolean newStatus) {
if (enabled == newStatus) return;

// Update config
enabled = newStatus;
setSave(PATH_ENABLED, newStatus);

// Reconnect websocket
eaPlugin.webSockets.reconnect("Config updated", SocketEndpoint.EVENT_CHAT);
}

public void setFormat(@NotNull String newFormat) {
if (format.equals(newFormat)) return;
format = newFormat;
setSave(PATH_FORMAT, newFormat);
}
}
}

public class MinecraftToDiscord {
@NotNull public static final String PATH_CONNECTIONS = PATH_MINECRAFT_TO_DISCORD + ".connections";

public boolean connections = getBoolean(PATH_CONNECTIONS, true);

public void setConnections(boolean newStatus) {
if (connections == newStatus) return;

// Update config
connections = newStatus;
setSave(PATH_CONNECTIONS, newStatus);

// Reconnect websocket
eaPlugin.webSockets.reconnect("Config updated", SocketEndpoint.PLAYER_CONNECTION);
}
}
}

public class Linking {
Expand Down Expand Up @@ -140,7 +188,7 @@ public class EventMessages {
public boolean enabled = getBoolean(PATH_ENABLED, true);
public boolean detectIps = getBoolean(PATH_DETECT_IPS);
public boolean soundEnabled = getBoolean(PATH_SOUND_ENABLED, true);
@Nullable public PlayableSound sound = getPlayableSound(PATH_SOUND).orElse(null);
@Nullable public final PlayableSound sound = getPlayableSound(PATH_SOUND).orElse(null);
@NotNull public final Set<EventType> ignoredTypes = getEnumSet(EventType.class, PATH_IGNORED_TYPES);
@NotNull public final Set<PingRole> ignoredPartnerRoles = getEnumSet(PingRole.class, PATH_IGNORED_PARTNER_ROLES);
@NotNull public final Set<EventFormat> ignoredFormats = getEnumSet(EventFormat.class, PATH_IGNORED_FORMATS);
Expand Down Expand Up @@ -168,8 +216,9 @@ private void loadHostFilter() {
@NotNull
private <T extends Enum<T>> Set<T> getEnumSet(@NotNull Class<T> enumClass, @NotNull String path) {
return getStringList(path).stream()
.map(string -> EventAlertsIntegration.getEnum(enumClass, string))
.filter(java.util.Objects::nonNull)
.map(string -> Mapper.toEnum(string, enumClass))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toSet());
}

Expand Down Expand Up @@ -198,7 +247,7 @@ public class Advanced {
@NotNull public static final String PATH_USE_TESTING_API = PATH_ADVANCED + ".use-testing-api";
@NotNull public static final String PATH_WEBSOCKETS = PATH_ADVANCED + ".websockets";

public boolean debug = getBoolean(PATH_DEBUG, false);
public final boolean debug = getBoolean(PATH_DEBUG, false);
public boolean useTestingApi = getBoolean(PATH_USE_TESTING_API, false);
@NotNull public final Websockets websockets = new Websockets();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


public enum EventType {
SKEPPY(true),
POTENTIAL_FAMOUS(true, "POTENTIAL FAMOUS"),
SKEPPY(true, "CREATOR"),
POTENTIAL_FAMOUS(true, "POTENTIAL SKEPPY"),
SIGHTING(true, "SKEPPY SIGHTING"),
FAMOUS(true),
FAMOUS(true, "CREATOR"),
PARTNER,
COMMUNITY;

Expand Down
Loading
Loading