11package gg .eventalerts .eventalertsintegration ;
22
3+ import gg .eventalerts .eventalertsintegration .config .ConfigCreator ;
34import gg .eventalerts .eventalertsintegration .config .ConfigYml ;
5+ import gg .eventalerts .eventalertsintegration .gui .GuiInputType ;
46import gg .eventalerts .eventalertsintegration .socket .WebSockets ;
57import net .kyori .adventure .text .Component ;
68import net .kyori .adventure .text .TextComponent ;
1214import org .jetbrains .annotations .NotNull ;
1315import xyz .srnyx .annoyingapi .AnnoyingPlugin ;
1416import xyz .srnyx .annoyingapi .PluginPlatform ;
17+ import xyz .srnyx .annoyingapi .libs .javautilities .HttpUtility ;
1518
1619import java .util .HashMap ;
1720import java .util .Map ;
1821import java .util .UUID ;
22+ import java .util .logging .Level ;
1923
2024
2125public 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