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
50 changes: 50 additions & 0 deletions Not Used/XBaseSerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gg.eventalerts.eventalertsintegration.config.serdes;

import com.cryptomorin.xseries.base.XBase;
import eu.okaeri.configs.schema.GenericsDeclaration;
import eu.okaeri.configs.serdes.DeserializationData;
import eu.okaeri.configs.serdes.ObjectSerializer;
import eu.okaeri.configs.serdes.SerializationData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;


public class XBaseSerializer<T extends XBase<T, ?>> implements ObjectSerializer<T> {
@NotNull private static final Map<Class<?>, Method> CACHED_METHODS = new HashMap<>();

@Override
public boolean supports(@NotNull Class<?> type) {
return XBase.class.isAssignableFrom(type);
}

@Override
public void serialize(@NotNull T object, @NotNull SerializationData data, @NotNull GenericsDeclaration generics) {
data.setValue(object.name());
}

@Override @Nullable
public T deserialize(@NotNull DeserializationData data, @NotNull GenericsDeclaration generics) {
final String name = data.getValue(String.class);
if (name == null) return null;

final Class<?> type = generics.getType();
Method method = CACHED_METHODS.get(type);
try {
// Method not cached, get and cache
if (method == null) {
method = type.getMethod("of", String.class);
CACHED_METHODS.put(type, method);
}

// Invoke method
return ((Optional<T>) method.invoke(null, name)).orElse(null);
} catch (final IllegalArgumentException | ReflectiveOperationException e) {
return null;
}
}
}
37 changes: 30 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("AvoidDuplicateDependencies")
import xyz.srnyx.gradlegalaxy.data.config.DependencyConfig
import xyz.srnyx.gradlegalaxy.data.config.JavaSetupConfig
import xyz.srnyx.gradlegalaxy.enums.Repository
Expand All @@ -20,40 +21,62 @@ 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 = "db46b2b"))
annoyingAPIConfig = DependencyConfig(version = "b69a3ab"))

// Runtime dependency versions
val okaeriConfigsVersion: String = "6.1.0-beta.4"
val javaWebSocketVersion: String = "1.6.0"
val bsonVersion: String = "5.7.0"
val triumphGuiVersion: String = "4.0.0-SNAPSHOT"
val jEmojiVersion: String = "2.0.0"

// Blossom (see java-templates module)
sourceSets.main { blossom.javaSources {
property("okaeri_configs_version", okaeriConfigsVersion)
property("java_websocket_version", javaWebSocketVersion)
property("bson_version", bsonVersion)
property("triumph_gui_version", triumphGuiVersion)
property("jemoji_version", jEmojiVersion)
} }

// Dependencies
// Repositories
repository("https://repo.okaeri.cloud/releases")
repository(Repository.TRIUMPH_SNAPSHOTS, Repository.PLACEHOLDER_API)
dependencies {
implementationRelocate("dev.triumphteam:triumph-gui-paper:4.0.0-SNAPSHOT", "dev.triumphteam")

compileOnly("org.java-websocket:Java-WebSocket:$javaWebSocketVersion") { // Downloaded on runtime
// Dependencies
dependencies {
// Downloaded on runtime
compileOnly("eu.okaeri:okaeri-configs-yaml-bukkit:$okaeriConfigsVersion") {
relocate("eu.okaeri")
}
compileOnly("eu.okaeri:okaeri-configs-serdes-commons:$okaeriConfigsVersion")
compileOnly("eu.okaeri:okaeri-configs-serdes-bukkit:$okaeriConfigsVersion")
compileOnly("eu.okaeri:okaeri-configs-validator-okaeri:$okaeriConfigsVersion")
compileOnly("org.java-websocket:Java-WebSocket:$javaWebSocketVersion") {
relocate("org.java_websocket")
}
compileOnly("org.mongodb:bson:$bsonVersion") { // Downloaded on runtime
compileOnly("org.mongodb:bson:$bsonVersion") {
relocate("org.bson")
relocate("org.checkerframework")
}
compileOnly("net.fellbaum:jemoji:$jEmojiVersion") { // Downloaded on runtime
compileOnly("dev.triumphteam:triumph-gui-paper:$triumphGuiVersion") {
relocate("dev.triumphteam")
}
compileOnly("net.fellbaum:jemoji:$jEmojiVersion") {
relocate("net.fellbaum")
}

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

// Unit tests
testImplementation("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
testImplementation("org.mongodb:bson:$bsonVersion")
testImplementation("eu.okaeri:okaeri-configs-core:$okaeriConfigsVersion")
testImplementation("eu.okaeri:okaeri-configs-yaml-bukkit:$okaeriConfigsVersion")
testImplementation("eu.okaeri:okaeri-configs-serdes-commons:$okaeriConfigsVersion")
testImplementation("eu.okaeri:okaeri-configs-serdes-bukkit:$okaeriConfigsVersion")
testImplementation("eu.okaeri:okaeri-configs-validator-okaeri:$okaeriConfigsVersion")
testImplementation(platform("org.junit:junit-bom:6.1.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ import org.jetbrains.annotations.NotNull;
* <br>Uses <a href="https://github.com/KyoriPowered/blossom">Blossom</a>
*/
public class BuildProperties {
/**
* The version of Java WebSocket that the plugin is built with
*/
@NotNull public static final String OKAERI_CONFIGS_VERSION = "{{ okaeri_configs_version }}";

@NotNull public static final String JAVA_WEBSOCKET_VERSION = "{{ java_websocket_version }}";

/**
* The version of BSON that the plugin is built with
*/
@NotNull public static final String BSON_VERSION = "{{ bson_version }}";

/**
* The version of JEmoji that the plugin is built with
*/
@NotNull public static final String TRIUMPH_GUI_VERSION = "{{ triumph_gui_version }}";

@NotNull public static final String JEMOJI_VERSION = "{{ jemoji_version }}";

/**
* This class cannot be instantiated
*/
public BuildProperties() {
throw new UnsupportedOperationException("This class cannot be instantiated");
}
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/gg/eventalerts/eventalertsintegration/EALibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,66 @@


public enum EALibrary implements AnnoyingLibrary {
/**
* {@code eu.okaeri:okaeri-configs-core}
*/
OKAERI_CONFIGS_CORE(
() -> Library.builder()
.repository("https://repo.okaeri.cloud/releases/")
.groupId("eu{}okaeri")
.artifactId("okaeri-configs-core")
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
/**
* {@code eu.okaeri:okaeri-configs-yaml-bukkit}
*/
OKAERI_CONFIGS_YAML_BUKKIT(
() -> Library.builder()
.repository("https://repo.okaeri.cloud/releases/")
.groupId("eu{}okaeri")
.artifactId("okaeri-configs-yaml-bukkit")
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
/**
* {@code eu.okaeri:okaeri-configs-serdes-commons}
*/
OKAERI_CONFIGS_SERDES_COMMONS(
() -> Library.builder()
.repository("https://repo.okaeri.cloud/releases/")
.groupId("eu{}okaeri")
.artifactId("okaeri-configs-serdes-commons")
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
/**
* {@code eu.okaeri:okaeri-configs-serdes-bukkit}
*/
OKAERI_CONFIGS_SERDES_BUKKIT(
() -> Library.builder()
.repository("https://repo.okaeri.cloud/releases/")
.groupId("eu{}okaeri")
.artifactId("okaeri-configs-serdes-bukkit")
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
/**
* {@code eu.okaeri:okaeri-validator}
*/
OKAERI_VALIDATOR(
() -> Library.builder()
.repository("https://repo.okaeri.cloud/releases/")
.groupId("eu{}okaeri")
.artifactId("okaeri-validator")
.version("2.0.5"),
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
/**
* {@code eu.okaeri:okaeri-configs-validator-okaeri}
*/
OKAERI_CONFIGS_VALIDATOR_OKAERI(
() -> Library.builder()
.repository("https://repo.okaeri.cloud/releases/")
.groupId("eu{}okaeri")
.artifactId("okaeri-configs-validator-okaeri")
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
/**
* {@code org.java-websocket:Java-WebSocket}
*/
Expand All @@ -37,6 +97,36 @@ public enum EALibrary implements AnnoyingLibrary {
plugin -> List.of(
plugin.getRelocation("org{}bson"),
plugin.getRelocation("org{}checkerframework"))), //TODO not sure if should include checkerframework here
/**
* {@code dev.triumphteam:nova}
*/
NOVA(
() -> Library.builder()
.repository("https://repo.triumphteam.dev/snapshots/")
.groupId("dev{}triumphteam")
.artifactId("nova")
.version("1.0.0-SNAPSHOT"),
plugin -> Collections.singleton(plugin.getRelocation("dev{}triumphteam"))),
/**
* {@code dev.triumphteam:triumph-gui-core}
*/
TRIUMPH_GUI_CORE(
() -> Library.builder()
.repository("https://repo.triumphteam.dev/snapshots/")
.groupId("dev{}triumphteam")
.artifactId("triumph-gui-core")
.version(BuildProperties.TRIUMPH_GUI_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("dev{}triumphteam"))),
/**
* {@code dev.triumphteam:triumph-gui-paper}
*/
TRIUMPH_GUI_PAPER(
() -> Library.builder()
.repository("https://repo.triumphteam.dev/snapshots/")
.groupId("dev{}triumphteam")
.artifactId("triumph-gui-paper")
.version(BuildProperties.TRIUMPH_GUI_VERSION),
plugin -> Collections.singleton(plugin.getRelocation("dev{}triumphteam"))),
/**
* {@code net.fellbaum:jememoji}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gg.eventalerts.eventalertsintegration;

import gg.eventalerts.eventalertsintegration.config.ConfigCreator;
import gg.eventalerts.eventalertsintegration.config.ConfigYml;
import gg.eventalerts.eventalertsintegration.gui.GuiInputType;
import gg.eventalerts.eventalertsintegration.socket.WebSockets;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
Expand All @@ -12,10 +14,12 @@
import org.jetbrains.annotations.NotNull;
import xyz.srnyx.annoyingapi.AnnoyingPlugin;
import xyz.srnyx.annoyingapi.PluginPlatform;
import xyz.srnyx.annoyingapi.libs.javautilities.HttpUtility;

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


public class EventAlertsIntegration extends AnnoyingPlugin {
Expand All @@ -32,12 +36,12 @@ public class EventAlertsIntegration extends AnnoyingPlugin {
.append(Component.text(" for more information"))
.build();

public ConfigYml config;
@NotNull public final ConfigYml config;
public WebSockets webSockets;
/**
* [player UUID, input key ID]
* [player UUID, pending GUI input target]
*/
@NotNull public final Map<UUID, String> guiInput = new HashMap<>();
@NotNull public final Map<UUID, GuiInputType> guiInput = new HashMap<>();

public EventAlertsIntegration() {
options
Expand All @@ -47,7 +51,20 @@ public EventAlertsIntegration() {
"gg.eventalerts.eventalertsintegration.commands",
"gg.eventalerts.eventalertsintegration.listeners");

// Load libraries
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_CORE);
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_YAML_BUKKIT);
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_SERDES_COMMONS);
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_SERDES_BUKKIT);
libraryManager.loadLibrary(EALibrary.OKAERI_VALIDATOR);
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_VALIDATOR_OKAERI);
libraryManager.loadLibrary(EALibrary.BSON);
libraryManager.loadLibrary(EALibrary.NOVA);
libraryManager.loadLibrary(EALibrary.TRIUMPH_GUI_CORE);
libraryManager.loadLibrary(EALibrary.TRIUMPH_GUI_PAPER);

// Configure config
config = ConfigCreator.create(this);
}

@Override
Expand All @@ -58,25 +75,29 @@ public void enable() {
@Override
public void reload() {
// Load config
config = new ConfigYml(this);
config.load(true);

// Toggle debug
setDebug(config.advanced.debug);

// Reconnect websockets
if (webSockets == null) webSockets = new WebSockets(this);
webSockets.reconnectAll("Plugin reload");
}

@Override
public void disable() {
webSockets.closeAll("Plugin disable");
if (webSockets != null) webSockets.closeAll("Plugin disable");
}

@NotNull
public String getApiHost() {
return config.advanced.useTestingApi ? "http://localhost:8080/api/v1/" : "https://eventalerts.gg/api/v1/";
return config.advanced.use_testing_api ? "http://localhost:8080/api/v1/" : "https://eventalerts.gg/api/v1/";
}

@NotNull
public String getSocketHost() {
return config.advanced.useTestingApi ? "ws://localhost:9090/api/v1/socket/" : "wss://eventalerts.gg/api/v1/socket/";
return config.advanced.use_testing_api ? "ws://localhost:9090/api/v1/socket/" : "wss://eventalerts.gg/api/v1/socket/";
}

@NotNull
Expand All @@ -88,11 +109,18 @@ public String getUserAgent() {
public Map<String, String> getSocketHeaders() {
final Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", getUserAgent());
if (config.apiKeys.playerApiKey != null) headers.put("X-Player-Key", config.apiKeys.playerApiKey);
if (config.apiKeys.serverApiKey != null) headers.put("X-Server-Key", config.apiKeys.serverApiKey);
final String playerKey = config.api_keys.getPlayer();
if (playerKey != null) headers.put("X-Player-Key", playerKey);
final String serverKey = config.api_keys.getServer();
if (serverKey != null) headers.put("X-Server-Key", serverKey);
return headers;
}

public void setDebug(boolean debug) {
AnnoyingPlugin.LOGGER.setLevel(debug ? Level.FINE : Level.INFO);
HttpUtility.DEBUG = debug;
}

public void runOnMainThread(@NotNull Runnable runnable) {
Bukkit.getScheduler().runTask(this, runnable);
}
Expand Down
Loading
Loading