Skip to content

Commit 427e1fa

Browse files
committed
Resolve merge conflict: Keep 1.19.x version range
2 parents 71aaa3a + 6a7fa95 commit 427e1fa

File tree

17 files changed

+53
-606
lines changed

17 files changed

+53
-606
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ build/
3838
.DS_Store
3939

4040
### Minecraft Test Server ###
41-
/src/test/resources/minecraft-test-server/*
41+
/src/test/resources/minecraft-test-server/*
42+
43+
test-server

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/shweit/serverapi/webhooks/RegisterWebHooks.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,45 @@ public static void sendToAllUrls(final JSONObject jsonObject) {
166166

167167
private static void sendWebHook(final String url, final JSONObject jsonObject) {
168168
try {
169-
HttpRequest request = HttpRequest.newBuilder()
170-
.uri(URI.create(url))
171-
.header("Content-Type", "application/json")
172-
.POST(HttpRequest.BodyPublishers.ofString(jsonObject.toString()))
169+
URI uri = URI.create(url);
170+
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
171+
.uri(uri);
172+
173+
// Check for Basic Authentication in URL
174+
String userInfo = uri.getUserInfo();
175+
if (userInfo != null && userInfo.contains(":")) {
176+
// Extract username and password from URL
177+
String[] credentials = userInfo.split(":", 2);
178+
String username = credentials[0];
179+
String password = credentials[1];
180+
181+
// Create Basic Auth header
182+
String auth = username + ":" + password;
183+
String encodedAuth = java.util.Base64.getEncoder().encodeToString(auth.getBytes());
184+
requestBuilder.header("Authorization", "Basic " + encodedAuth);
185+
186+
// Rebuild URI without auth info
187+
String cleanUrl = url.replaceFirst(userInfo + "@", "");
188+
uri = URI.create(cleanUrl);
189+
requestBuilder.uri(uri);
190+
}
191+
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+
206+
HttpRequest request = requestBuilder
207+
.POST(HttpRequest.BodyPublishers.ofString(bodyContent))
173208
.build();
174209

175210
CompletableFuture<HttpResponse<String>> response = HTTP_CLIENT.sendAsync(request, HttpResponse.BodyHandlers.ofString());
@@ -178,15 +213,16 @@ private static void sendWebHook(final String url, final JSONObject jsonObject) {
178213
if (httpResponse.statusCode() == 200) {
179214
Logger.debug("WebHook '" + jsonObject.get("event") + "' erfolgreich an " + url + "gesendet");
180215
} else {
181-
Logger.warning("Fehler beim Senden des WebHooks '" + jsonObject.get("event") + "' an " + url + ". Antwortcode: " + httpResponse.statusCode());
216+
Logger.warning("Error while sending webhook event '" + jsonObject.get("event") + "' to " + url + ". Responde Code: " + httpResponse.statusCode());
217+
Logger.warning(httpResponse.body());
182218
}
183219
}).exceptionally(e -> {
184-
Logger.error("Fehler beim Senden des WebHooks " + jsonObject.get("event") + " an " + url + ": " + e.getMessage());
220+
Logger.error("Error while sending webhook event " + jsonObject.get("event") + " to " + url + ": " + e.getMessage());
185221
return null;
186222
});
187223

188224
} catch (Exception e) {
189-
Logger.error("Fehler beim Senden des WebHooks " + jsonObject.get("event") + " an " + url + ": " + e.getMessage());
225+
Logger.error("Error while sending webhook event " + jsonObject.get("event") + " to " + url + ": " + e.getMessage());
190226
}
191227
}
192228

src/main/resources/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ webhooks:
2525
urls:
2626
- "https://example.com/webhook1"
2727
- "https://example.com/webhook2"
28+
29+
# If set to true, only the message content will be sent to the webhook endpoints
30+
# instead of the full JSON object with event, load_type, and message fields.
31+
# Example with onlyMessage: false -> {"load_type":"STARTUP","event":"server_start","message":"Server has started"}
32+
# Example with onlyMessage: true -> "Server has started"
33+
onlyMessage: false
2834

2935
# Here is a list of all available Webhooks.
3036
# You can enable or disable them here.

src/test/java/ApiTestHelper.java

Lines changed: 0 additions & 179 deletions
This file was deleted.

src/test/java/PlayerAPITest.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)