@@ -168,8 +168,7 @@ private static void sendWebHook(final String url, final JSONObject jsonObject) {
168168 try {
169169 URI uri = URI .create (url );
170170 HttpRequest .Builder requestBuilder = HttpRequest .newBuilder ()
171- .uri (uri )
172- .header ("Content-Type" , "application/json" );
171+ .uri (uri );
173172
174173 // Check for Basic Authentication in URL
175174 String userInfo = uri .getUserInfo ();
@@ -190,8 +189,22 @@ private static void sendWebHook(final String url, final JSONObject jsonObject) {
190189 requestBuilder .uri (uri );
191190 }
192191
192+ // Check if only message should be sent
193+ boolean onlyMessage = MinecraftServerAPI .config .getBoolean ("webhooks.onlyMessage" , false );
194+ String bodyContent ;
195+
196+ if (onlyMessage && jsonObject .has ("message" )) {
197+ // Send only the message content as plain text
198+ bodyContent = jsonObject .getString ("message" );
199+ requestBuilder .header ("Content-Type" , "text/plain; charset=UTF-8" );
200+ } else {
201+ // Send full JSON object
202+ bodyContent = jsonObject .toString ();
203+ requestBuilder .header ("Content-Type" , "application/json" );
204+ }
205+
193206 HttpRequest request = requestBuilder
194- .POST (HttpRequest .BodyPublishers .ofString (jsonObject . toString () ))
207+ .POST (HttpRequest .BodyPublishers .ofString (bodyContent ))
195208 .build ();
196209
197210 CompletableFuture <HttpResponse <String >> response = HTTP_CLIENT .sendAsync (request , HttpResponse .BodyHandlers .ofString ());
0 commit comments