Skip to content

Commit 85d037a

Browse files
authored
Merge pull request #10 from Event-Alerts/okaeri-configs
Okaeri Configs
2 parents 0a540eb + 893b8df commit 85d037a

49 files changed

Lines changed: 1775 additions & 822 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Not Used/XBaseSerializer.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package gg.eventalerts.eventalertsintegration.config.serdes;
2+
3+
import com.cryptomorin.xseries.base.XBase;
4+
import eu.okaeri.configs.schema.GenericsDeclaration;
5+
import eu.okaeri.configs.serdes.DeserializationData;
6+
import eu.okaeri.configs.serdes.ObjectSerializer;
7+
import eu.okaeri.configs.serdes.SerializationData;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.lang.reflect.Method;
12+
import java.util.HashMap;
13+
import java.util.Map;
14+
import java.util.Optional;
15+
16+
17+
public class XBaseSerializer<T extends XBase<T, ?>> implements ObjectSerializer<T> {
18+
@NotNull private static final Map<Class<?>, Method> CACHED_METHODS = new HashMap<>();
19+
20+
@Override
21+
public boolean supports(@NotNull Class<?> type) {
22+
return XBase.class.isAssignableFrom(type);
23+
}
24+
25+
@Override
26+
public void serialize(@NotNull T object, @NotNull SerializationData data, @NotNull GenericsDeclaration generics) {
27+
data.setValue(object.name());
28+
}
29+
30+
@Override @Nullable
31+
public T deserialize(@NotNull DeserializationData data, @NotNull GenericsDeclaration generics) {
32+
final String name = data.getValue(String.class);
33+
if (name == null) return null;
34+
35+
final Class<?> type = generics.getType();
36+
Method method = CACHED_METHODS.get(type);
37+
try {
38+
// Method not cached, get and cache
39+
if (method == null) {
40+
method = type.getMethod("of", String.class);
41+
CACHED_METHODS.put(type, method);
42+
}
43+
44+
// Invoke method
45+
return ((Optional<T>) method.invoke(null, name)).orElse(null);
46+
} catch (final IllegalArgumentException | ReflectiveOperationException e) {
47+
return null;
48+
}
49+
}
50+
}

build.gradle.kts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@file:Suppress("AvoidDuplicateDependencies")
12
import xyz.srnyx.gradlegalaxy.data.config.DependencyConfig
23
import xyz.srnyx.gradlegalaxy.data.config.JavaSetupConfig
34
import xyz.srnyx.gradlegalaxy.enums.Repository
@@ -20,40 +21,62 @@ setupAnnoyingAPI(
2021
version = "1.1.0",
2122
description = "A plugin to integrate your Minecraft server with the Event Alerts ecosystem",
2223
javaVersion = JavaVersion.VERSION_21),
23-
annoyingAPIConfig = DependencyConfig(version = "db46b2b"))
24+
annoyingAPIConfig = DependencyConfig(version = "b69a3ab"))
2425

2526
// Runtime dependency versions
27+
val okaeriConfigsVersion: String = "6.1.0-beta.4"
2628
val javaWebSocketVersion: String = "1.6.0"
2729
val bsonVersion: String = "5.7.0"
30+
val triumphGuiVersion: String = "4.0.0-SNAPSHOT"
2831
val jEmojiVersion: String = "2.0.0"
2932

3033
// Blossom (see java-templates module)
3134
sourceSets.main { blossom.javaSources {
35+
property("okaeri_configs_version", okaeriConfigsVersion)
3236
property("java_websocket_version", javaWebSocketVersion)
3337
property("bson_version", bsonVersion)
38+
property("triumph_gui_version", triumphGuiVersion)
3439
property("jemoji_version", jEmojiVersion)
3540
} }
3641

37-
// Dependencies
42+
// Repositories
43+
repository("https://repo.okaeri.cloud/releases")
3844
repository(Repository.TRIUMPH_SNAPSHOTS, Repository.PLACEHOLDER_API)
39-
dependencies {
40-
implementationRelocate("dev.triumphteam:triumph-gui-paper:4.0.0-SNAPSHOT", "dev.triumphteam")
4145

42-
compileOnly("org.java-websocket:Java-WebSocket:$javaWebSocketVersion") { // Downloaded on runtime
46+
// Dependencies
47+
dependencies {
48+
// Downloaded on runtime
49+
compileOnly("eu.okaeri:okaeri-configs-yaml-bukkit:$okaeriConfigsVersion") {
50+
relocate("eu.okaeri")
51+
}
52+
compileOnly("eu.okaeri:okaeri-configs-serdes-commons:$okaeriConfigsVersion")
53+
compileOnly("eu.okaeri:okaeri-configs-serdes-bukkit:$okaeriConfigsVersion")
54+
compileOnly("eu.okaeri:okaeri-configs-validator-okaeri:$okaeriConfigsVersion")
55+
compileOnly("org.java-websocket:Java-WebSocket:$javaWebSocketVersion") {
4356
relocate("org.java_websocket")
4457
}
45-
compileOnly("org.mongodb:bson:$bsonVersion") { // Downloaded on runtime
58+
compileOnly("org.mongodb:bson:$bsonVersion") {
4659
relocate("org.bson")
4760
relocate("org.checkerframework")
4861
}
49-
compileOnly("net.fellbaum:jemoji:$jEmojiVersion") { // Downloaded on runtime
62+
compileOnly("dev.triumphteam:triumph-gui-paper:$triumphGuiVersion") {
63+
relocate("dev.triumphteam")
64+
}
65+
compileOnly("net.fellbaum:jemoji:$jEmojiVersion") {
5066
relocate("net.fellbaum")
5167
}
5268

69+
// Optional
5370
compileOnly("me.clip:placeholderapi:2.12.2")
5471

72+
// Unit tests
5573
testImplementation("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
5674
testImplementation("org.mongodb:bson:$bsonVersion")
75+
testImplementation("eu.okaeri:okaeri-configs-core:$okaeriConfigsVersion")
76+
testImplementation("eu.okaeri:okaeri-configs-yaml-bukkit:$okaeriConfigsVersion")
77+
testImplementation("eu.okaeri:okaeri-configs-serdes-commons:$okaeriConfigsVersion")
78+
testImplementation("eu.okaeri:okaeri-configs-serdes-bukkit:$okaeriConfigsVersion")
79+
testImplementation("eu.okaeri:okaeri-configs-validator-okaeri:$okaeriConfigsVersion")
5780
testImplementation(platform("org.junit:junit-bom:6.1.0"))
5881
testImplementation("org.junit.jupiter:junit-jupiter")
5982
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

src/main/java-templates/gg/eventalerts/eventalertsintegration/BuildProperties.java.peb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@ import org.jetbrains.annotations.NotNull;
88
* <br>Uses <a href="https://github.com/KyoriPowered/blossom">Blossom</a>
99
*/
1010
public class BuildProperties {
11-
/**
12-
* The version of Java WebSocket that the plugin is built with
13-
*/
11+
@NotNull public static final String OKAERI_CONFIGS_VERSION = "{{ okaeri_configs_version }}";
12+
1413
@NotNull public static final String JAVA_WEBSOCKET_VERSION = "{{ java_websocket_version }}";
1514

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

21-
/**
22-
* The version of JEmoji that the plugin is built with
23-
*/
17+
@NotNull public static final String TRIUMPH_GUI_VERSION = "{{ triumph_gui_version }}";
18+
2419
@NotNull public static final String JEMOJI_VERSION = "{{ jemoji_version }}";
2520

26-
/**
27-
* This class cannot be instantiated
28-
*/
2921
public BuildProperties() {
3022
throw new UnsupportedOperationException("This class cannot be instantiated");
3123
}

src/main/java/gg/eventalerts/eventalertsintegration/EALibrary.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,66 @@
1515

1616

1717
public enum EALibrary implements AnnoyingLibrary {
18+
/**
19+
* {@code eu.okaeri:okaeri-configs-core}
20+
*/
21+
OKAERI_CONFIGS_CORE(
22+
() -> Library.builder()
23+
.repository("https://repo.okaeri.cloud/releases/")
24+
.groupId("eu{}okaeri")
25+
.artifactId("okaeri-configs-core")
26+
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
27+
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
28+
/**
29+
* {@code eu.okaeri:okaeri-configs-yaml-bukkit}
30+
*/
31+
OKAERI_CONFIGS_YAML_BUKKIT(
32+
() -> Library.builder()
33+
.repository("https://repo.okaeri.cloud/releases/")
34+
.groupId("eu{}okaeri")
35+
.artifactId("okaeri-configs-yaml-bukkit")
36+
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
37+
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
38+
/**
39+
* {@code eu.okaeri:okaeri-configs-serdes-commons}
40+
*/
41+
OKAERI_CONFIGS_SERDES_COMMONS(
42+
() -> Library.builder()
43+
.repository("https://repo.okaeri.cloud/releases/")
44+
.groupId("eu{}okaeri")
45+
.artifactId("okaeri-configs-serdes-commons")
46+
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
47+
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
48+
/**
49+
* {@code eu.okaeri:okaeri-configs-serdes-bukkit}
50+
*/
51+
OKAERI_CONFIGS_SERDES_BUKKIT(
52+
() -> Library.builder()
53+
.repository("https://repo.okaeri.cloud/releases/")
54+
.groupId("eu{}okaeri")
55+
.artifactId("okaeri-configs-serdes-bukkit")
56+
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
57+
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
58+
/**
59+
* {@code eu.okaeri:okaeri-validator}
60+
*/
61+
OKAERI_VALIDATOR(
62+
() -> Library.builder()
63+
.repository("https://repo.okaeri.cloud/releases/")
64+
.groupId("eu{}okaeri")
65+
.artifactId("okaeri-validator")
66+
.version("2.0.5"),
67+
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
68+
/**
69+
* {@code eu.okaeri:okaeri-configs-validator-okaeri}
70+
*/
71+
OKAERI_CONFIGS_VALIDATOR_OKAERI(
72+
() -> Library.builder()
73+
.repository("https://repo.okaeri.cloud/releases/")
74+
.groupId("eu{}okaeri")
75+
.artifactId("okaeri-configs-validator-okaeri")
76+
.version(BuildProperties.OKAERI_CONFIGS_VERSION),
77+
plugin -> Collections.singleton(plugin.getRelocation("eu{}okaeri"))),
1878
/**
1979
* {@code org.java-websocket:Java-WebSocket}
2080
*/
@@ -37,6 +97,36 @@ public enum EALibrary implements AnnoyingLibrary {
3797
plugin -> List.of(
3898
plugin.getRelocation("org{}bson"),
3999
plugin.getRelocation("org{}checkerframework"))), //TODO not sure if should include checkerframework here
100+
/**
101+
* {@code dev.triumphteam:nova}
102+
*/
103+
NOVA(
104+
() -> Library.builder()
105+
.repository("https://repo.triumphteam.dev/snapshots/")
106+
.groupId("dev{}triumphteam")
107+
.artifactId("nova")
108+
.version("1.0.0-SNAPSHOT"),
109+
plugin -> Collections.singleton(plugin.getRelocation("dev{}triumphteam"))),
110+
/**
111+
* {@code dev.triumphteam:triumph-gui-core}
112+
*/
113+
TRIUMPH_GUI_CORE(
114+
() -> Library.builder()
115+
.repository("https://repo.triumphteam.dev/snapshots/")
116+
.groupId("dev{}triumphteam")
117+
.artifactId("triumph-gui-core")
118+
.version(BuildProperties.TRIUMPH_GUI_VERSION),
119+
plugin -> Collections.singleton(plugin.getRelocation("dev{}triumphteam"))),
120+
/**
121+
* {@code dev.triumphteam:triumph-gui-paper}
122+
*/
123+
TRIUMPH_GUI_PAPER(
124+
() -> Library.builder()
125+
.repository("https://repo.triumphteam.dev/snapshots/")
126+
.groupId("dev{}triumphteam")
127+
.artifactId("triumph-gui-paper")
128+
.version(BuildProperties.TRIUMPH_GUI_VERSION),
129+
plugin -> Collections.singleton(plugin.getRelocation("dev{}triumphteam"))),
40130
/**
41131
* {@code net.fellbaum:jememoji}
42132
*/

src/main/java/gg/eventalerts/eventalertsintegration/EventAlertsIntegration.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package gg.eventalerts.eventalertsintegration;
22

3+
import gg.eventalerts.eventalertsintegration.config.ConfigCreator;
34
import gg.eventalerts.eventalertsintegration.config.ConfigYml;
5+
import gg.eventalerts.eventalertsintegration.gui.GuiInputType;
46
import gg.eventalerts.eventalertsintegration.socket.WebSockets;
57
import net.kyori.adventure.text.Component;
68
import net.kyori.adventure.text.TextComponent;
@@ -12,10 +14,12 @@
1214
import org.jetbrains.annotations.NotNull;
1315
import xyz.srnyx.annoyingapi.AnnoyingPlugin;
1416
import xyz.srnyx.annoyingapi.PluginPlatform;
17+
import xyz.srnyx.annoyingapi.libs.javautilities.HttpUtility;
1518

1619
import java.util.HashMap;
1720
import java.util.Map;
1821
import java.util.UUID;
22+
import java.util.logging.Level;
1923

2024

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

35-
public ConfigYml config;
39+
@NotNull public final ConfigYml config;
3640
public WebSockets webSockets;
3741
/**
38-
* [player UUID, input key ID]
42+
* [player UUID, pending GUI input target]
3943
*/
40-
@NotNull public final Map<UUID, String> guiInput = new HashMap<>();
44+
@NotNull public final Map<UUID, GuiInputType> guiInput = new HashMap<>();
4145

4246
public EventAlertsIntegration() {
4347
options
@@ -47,7 +51,20 @@ public EventAlertsIntegration() {
4751
"gg.eventalerts.eventalertsintegration.commands",
4852
"gg.eventalerts.eventalertsintegration.listeners");
4953

54+
// Load libraries
55+
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_CORE);
56+
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_YAML_BUKKIT);
57+
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_SERDES_COMMONS);
58+
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_SERDES_BUKKIT);
59+
libraryManager.loadLibrary(EALibrary.OKAERI_VALIDATOR);
60+
libraryManager.loadLibrary(EALibrary.OKAERI_CONFIGS_VALIDATOR_OKAERI);
5061
libraryManager.loadLibrary(EALibrary.BSON);
62+
libraryManager.loadLibrary(EALibrary.NOVA);
63+
libraryManager.loadLibrary(EALibrary.TRIUMPH_GUI_CORE);
64+
libraryManager.loadLibrary(EALibrary.TRIUMPH_GUI_PAPER);
65+
66+
// Configure config
67+
config = ConfigCreator.create(this);
5168
}
5269

5370
@Override
@@ -58,25 +75,29 @@ public void enable() {
5875
@Override
5976
public void reload() {
6077
// Load config
61-
config = new ConfigYml(this);
78+
config.load(true);
79+
80+
// Toggle debug
81+
setDebug(config.advanced.debug);
82+
6283
// Reconnect websockets
6384
if (webSockets == null) webSockets = new WebSockets(this);
6485
webSockets.reconnectAll("Plugin reload");
6586
}
6687

6788
@Override
6889
public void disable() {
69-
webSockets.closeAll("Plugin disable");
90+
if (webSockets != null) webSockets.closeAll("Plugin disable");
7091
}
7192

7293
@NotNull
7394
public String getApiHost() {
74-
return config.advanced.useTestingApi ? "http://localhost:8080/api/v1/" : "https://eventalerts.gg/api/v1/";
95+
return config.advanced.use_testing_api ? "http://localhost:8080/api/v1/" : "https://eventalerts.gg/api/v1/";
7596
}
7697

7798
@NotNull
7899
public String getSocketHost() {
79-
return config.advanced.useTestingApi ? "ws://localhost:9090/api/v1/socket/" : "wss://eventalerts.gg/api/v1/socket/";
100+
return config.advanced.use_testing_api ? "ws://localhost:9090/api/v1/socket/" : "wss://eventalerts.gg/api/v1/socket/";
80101
}
81102

82103
@NotNull
@@ -88,11 +109,18 @@ public String getUserAgent() {
88109
public Map<String, String> getSocketHeaders() {
89110
final Map<String, String> headers = new HashMap<>();
90111
headers.put("User-Agent", getUserAgent());
91-
if (config.apiKeys.playerApiKey != null) headers.put("X-Player-Key", config.apiKeys.playerApiKey);
92-
if (config.apiKeys.serverApiKey != null) headers.put("X-Server-Key", config.apiKeys.serverApiKey);
112+
final String playerKey = config.api_keys.getPlayer();
113+
if (playerKey != null) headers.put("X-Player-Key", playerKey);
114+
final String serverKey = config.api_keys.getServer();
115+
if (serverKey != null) headers.put("X-Server-Key", serverKey);
93116
return headers;
94117
}
95118

119+
public void setDebug(boolean debug) {
120+
AnnoyingPlugin.LOGGER.setLevel(debug ? Level.FINE : Level.INFO);
121+
HttpUtility.DEBUG = debug;
122+
}
123+
96124
public void runOnMainThread(@NotNull Runnable runnable) {
97125
Bukkit.getScheduler().runTask(this, runnable);
98126
}

0 commit comments

Comments
 (0)