From d038410c269cb97740a7cbb109f7f00edbd0f96b Mon Sep 17 00:00:00 2001 From: OmegaSunkey Date: Thu, 16 Apr 2026 23:27:55 -0500 Subject: [PATCH 1/5] feat: Thread support in Hook.java --- .../com/github/pinmacaroon/dchook/Hook.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/pinmacaroon/dchook/Hook.java b/src/main/java/com/github/pinmacaroon/dchook/Hook.java index b6e2385..f033efe 100644 --- a/src/main/java/com/github/pinmacaroon/dchook/Hook.java +++ b/src/main/java/com/github/pinmacaroon/dchook/Hook.java @@ -47,6 +47,7 @@ public class Hook implements DedicatedServerModInitializer { public static volatile Bot BOT; public static boolean BOT_ENABLED = false; + private boolean IS_THREAD = false; private static MinecraftServer MINECRAFT_SERVER; public static MinecraftServer getGameServer() { @@ -73,11 +74,19 @@ public void onInitializeServer() { if(ModConfigs.FUNCTIONS_BOT_ENABLED) bottedStart(); else botlessStart(); + + if(ModConfigs.IS_THREAD) IS_THREAD = true; try { + URI webhook_url; + if(ModConfigs.IS_THREAD) { + webhook_url = URI.create(ModConfigs.WEBHOOK_URL + "?thread_id=" + ModConfigs.THREAD_ID); + } else { + webhook_url = URI.create(ModConfigs.WEBHOOK_URL); + } HttpRequest get_webhook = HttpRequest.newBuilder() .GET() - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(webhook_url) .build(); HttpResponse response = HTTPCLIENT.send(get_webhook, HttpResponse.BodyHandlers.ofString()); @@ -96,7 +105,11 @@ public void onInitializeServer() { Thread.onSpinWait(); } BOT.setGUILD_ID(body.get("guild_id").getAsLong()); - BOT.setCHANNEL_ID(body.get("channel_id").getAsLong()); + if (IS_THREAD) { + BOT.setCHANNEL_ID(Long.parseLong(ModConfigs.THREAD_ID)); + } else { + BOT.setCHANNEL_ID(body.get("channel_id").getAsLong()); + } }); bot_rutime_thread.start(); } @@ -129,4 +142,4 @@ private void bottedStart(){ e.printStackTrace(); } } -} \ No newline at end of file +} From 8421e81519ad83654bf8562ab6b911aad55d6aab Mon Sep 17 00:00:00 2001 From: OmegaSunkey Date: Thu, 16 Apr 2026 23:28:23 -0500 Subject: [PATCH 2/5] feat: Add thread configs --- .../com/github/pinmacaroon/dchook/conf/ModConfigs.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java b/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java index 0f76478..20e6a45 100644 --- a/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java +++ b/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java @@ -8,6 +8,7 @@ public class ModConfigs { public static SimpleConfig CONFIG; public static String WEBHOOK_URL; + public static String THREAD_ID; public static String MESSAGES_SERVER_STARTING; public static String MESSAGES_SERVER_STOPPED; public static String MESSAGES_SERVER_STARTED; @@ -16,6 +17,7 @@ public class ModConfigs { public static String MESSAGES_BOT_LIST; public static String MESSAGES_BOT_MODS_LIST; public static String MESSAGES_BOT_MODS_NONE; + public static boolean IS_THREAD; public static boolean FUNCTIONS_ALLOWOOCMESSAGES; public static boolean MESSAGES_SERVER_STARTING_ALLOWED; public static boolean MESSAGES_SERVER_STOPPED_ALLOWED; @@ -52,7 +54,11 @@ private static void createConfigs() { configs.addDocumentationLine("Configure Discord connection related parameters:"); configs.addKeyValuePair(new Pair<>("webhook.url", "https://discord.com/api/webhooks/000/ABCDEF"), "url of webhook"); - configs.addBlankLine(); + configs.addDocumentationLine("Configure if webhook points to a thread"); + configs.addKeyValuePair(new Pair<>("webhook.thread", false), "is channel a thread?"); + configs.addDocumentationLine("Configure Thread ID if true. DON'T ADD ?thread_id PARAMETER TO THE WEBHOOK AS THE MOD AUTOMATICALLY INSERTS IT!"); + configs.addKeyValuePair(new Pair<>("webhook.thread.id", "01234567890123456789"), "id of thread"); + configs.addBlankLine(); configs.addDocumentationLine("Configure messages sent:"); configs.addKeyValuePair(new Pair<>("messages.server.starting", "The server is starting!"), "start message"); @@ -78,6 +84,8 @@ private static void createConfigs() { private static void assignConfigs() { WEBHOOK_URL = CONFIG.getOrDefault("webhook.url", ""); + IS_THREAD = CONFIG.getOrDefault("webhook.thread", false); + THREAD_ID = CONFIG.getOrDefault("webhook.thread.id", ""); MESSAGES_SERVER_STARTING = CONFIG.getOrDefault("messages.server.starting", "messages.server.starting"); MESSAGES_SERVER_STARTED = CONFIG.getOrDefault("messages.server.started", "messages.server.started"); MESSAGES_SERVER_STOPPED = CONFIG.getOrDefault("messages.server.stopped", "messages.server.stopped"); From a4747df949ff0b1f2d8aa71ddb34cce6530f8b1f Mon Sep 17 00:00:00 2001 From: OmegaSunkey Date: Thu, 16 Apr 2026 23:38:50 -0500 Subject: [PATCH 3/5] fix: formatting issue --- .../github/pinmacaroon/dchook/conf/ModConfigs.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java b/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java index 20e6a45..501933a 100644 --- a/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java +++ b/src/main/java/com/github/pinmacaroon/dchook/conf/ModConfigs.java @@ -54,11 +54,11 @@ private static void createConfigs() { configs.addDocumentationLine("Configure Discord connection related parameters:"); configs.addKeyValuePair(new Pair<>("webhook.url", "https://discord.com/api/webhooks/000/ABCDEF"), "url of webhook"); - configs.addDocumentationLine("Configure if webhook points to a thread"); - configs.addKeyValuePair(new Pair<>("webhook.thread", false), "is channel a thread?"); - configs.addDocumentationLine("Configure Thread ID if true. DON'T ADD ?thread_id PARAMETER TO THE WEBHOOK AS THE MOD AUTOMATICALLY INSERTS IT!"); - configs.addKeyValuePair(new Pair<>("webhook.thread.id", "01234567890123456789"), "id of thread"); - configs.addBlankLine(); + configs.addDocumentationLine("Configure if webhook points to a thread"); + configs.addKeyValuePair(new Pair<>("webhook.thread", false), "is channel a thread?"); + configs.addDocumentationLine("Configure Thread ID if true. DON'T ADD ?thread_id PARAMETER TO THE WEBHOOK AS THE MOD AUTOMATICALLY INSERTS IT!"); + configs.addKeyValuePair(new Pair<>("webhook.thread.id", "01234567890123456789"), "id of thread"); + configs.addBlankLine(); configs.addDocumentationLine("Configure messages sent:"); configs.addKeyValuePair(new Pair<>("messages.server.starting", "The server is starting!"), "start message"); @@ -84,8 +84,8 @@ private static void createConfigs() { private static void assignConfigs() { WEBHOOK_URL = CONFIG.getOrDefault("webhook.url", ""); - IS_THREAD = CONFIG.getOrDefault("webhook.thread", false); - THREAD_ID = CONFIG.getOrDefault("webhook.thread.id", ""); + IS_THREAD = CONFIG.getOrDefault("webhook.thread", false); + THREAD_ID = CONFIG.getOrDefault("webhook.thread.id", ""); MESSAGES_SERVER_STARTING = CONFIG.getOrDefault("messages.server.starting", "messages.server.starting"); MESSAGES_SERVER_STARTED = CONFIG.getOrDefault("messages.server.started", "messages.server.started"); MESSAGES_SERVER_STOPPED = CONFIG.getOrDefault("messages.server.stopped", "messages.server.stopped"); From 9b6fe15019c55ef8823e9f73cd11b9c5ea3e0a9c Mon Sep 17 00:00:00 2001 From: OmegaSunkey Date: Thu, 16 Apr 2026 23:43:42 -0500 Subject: [PATCH 4/5] feat: Threads support --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 91934aa..19b176d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.16.10 tserver_mcver=1.21.1 # Mod Properties -mod_version=1.1.0+fabric.1.21.1 +mod_version=1.1.1+fabric.1.21.1 maven_group=com.github.pinmacaroon.dchook archives_base_name=dchook From 58f12677228b4834052b55a5199ffafe89d7952d Mon Sep 17 00:00:00 2001 From: OmegaSunkey Date: Fri, 17 Apr 2026 01:07:48 -0500 Subject: [PATCH 5/5] fix: Send events inside thread --- .../com/github/pinmacaroon/dchook/Hook.java | 21 ++++++++++--------- .../dchook/util/EventListeners.java | 15 ++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/github/pinmacaroon/dchook/Hook.java b/src/main/java/com/github/pinmacaroon/dchook/Hook.java index f033efe..2bfd367 100644 --- a/src/main/java/com/github/pinmacaroon/dchook/Hook.java +++ b/src/main/java/com/github/pinmacaroon/dchook/Hook.java @@ -44,6 +44,8 @@ public class Hook implements DedicatedServerModInitializer { "^https:\\/\\/(ptb\\.|canary\\.)?discord\\.com\\/api\\/webhooks\\/\\d+\\/.+$" ); + public static URI WEBHOOK_URI; + public static volatile Bot BOT; public static boolean BOT_ENABLED = false; @@ -75,18 +77,17 @@ public void onInitializeServer() { if(ModConfigs.FUNCTIONS_BOT_ENABLED) bottedStart(); else botlessStart(); - if(ModConfigs.IS_THREAD) IS_THREAD = true; - - try { - URI webhook_url; - if(ModConfigs.IS_THREAD) { - webhook_url = URI.create(ModConfigs.WEBHOOK_URL + "?thread_id=" + ModConfigs.THREAD_ID); - } else { - webhook_url = URI.create(ModConfigs.WEBHOOK_URL); - } + if(ModConfigs.IS_THREAD) { + IS_THREAD = true; + WEBHOOK_URI = URI.create(ModConfigs.WEBHOOK_URL + "?thread_id=" + ModConfigs.THREAD_ID); + } else { + WEBHOOK_URI = URI.create(ModConfigs.WEBHOOK_URL); + } + + try { HttpRequest get_webhook = HttpRequest.newBuilder() .GET() - .uri(webhook_url) + .uri(WEBHOOK_URI) .build(); HttpResponse response = HTTPCLIENT.send(get_webhook, HttpResponse.BodyHandlers.ofString()); diff --git a/src/main/java/com/github/pinmacaroon/dchook/util/EventListeners.java b/src/main/java/com/github/pinmacaroon/dchook/util/EventListeners.java index ad7163c..c3bbaae 100644 --- a/src/main/java/com/github/pinmacaroon/dchook/util/EventListeners.java +++ b/src/main/java/com/github/pinmacaroon/dchook/util/EventListeners.java @@ -12,6 +12,7 @@ import java.net.http.HttpResponse; import java.text.MessageFormat; import java.util.HashMap; +import java.util.ArrayList; import java.util.concurrent.ExecutionException; public class EventListeners { @@ -28,7 +29,7 @@ public static void registerEventListeners(){ HttpRequest post = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(Hook.GSON.toJson(request_body))) - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(Hook.WEBHOOK_URI) .header("Content-Type", "application/json") .build(); @@ -48,7 +49,7 @@ public static void registerEventListeners(){ HttpRequest post = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(Hook.GSON.toJson(request_body))) - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(Hook.WEBHOOK_URI) .header("Content-Type", "application/json") .build(); @@ -60,7 +61,7 @@ public static void registerEventListeners(){ } if (ModConfigs.FUNCTIONS_PROMOTIONS_ENABLED) { - PromotionProvider.sendPromotion(URI.create(ModConfigs.WEBHOOK_URL)); + PromotionProvider.sendPromotion(Hook.WEBHOOK_URI); } }); @@ -72,7 +73,7 @@ public static void registerEventListeners(){ HttpRequest post = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(Hook.GSON.toJson(request_body))) - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(Hook.WEBHOOK_URI) .header("Content-Type", "application/json") .build(); @@ -94,7 +95,7 @@ public static void registerEventListeners(){ HttpRequest post = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(Hook.GSON.toJson(request_body))) - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(Hook.WEBHOOK_URI) .header("Content-Type", "application/json") .build(); @@ -126,7 +127,7 @@ public static void registerEventListeners(){ HttpRequest post = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(Hook.GSON.toJson(request_body))) - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(Hook.WEBHOOK_URI) .header("Content-Type", "application/json") .build(); @@ -146,7 +147,7 @@ public static void registerEventListeners(){ HttpRequest post = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(Hook.GSON.toJson(request_body))) - .uri(URI.create(ModConfigs.WEBHOOK_URL)) + .uri(Hook.WEBHOOK_URI) .header("Content-Type", "application/json") .build();