Skip to content

Commit d396ee5

Browse files
committed
added bit more structure to common
1 parent 7594ee9 commit d396ee5

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

luckprefix-common/src/main/java/de/eztxm/luckprefix/common/util/Hastebin.java renamed to luckprefix-common/src/main/java/de/eztxm/luckprefix/common/logging/LuckPaste.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
1-
package de.eztxm.luckprefix.common.util;
1+
package de.eztxm.luckprefix.common.logging;
22

33
import java.io.*;
44
import java.net.HttpURLConnection;
5+
import java.net.URI;
56
import java.net.URL;
67
import java.nio.charset.StandardCharsets;
78

8-
public final class Hastebin {
9-
private Hastebin() {}
9+
public final class LuckPaste {
10+
private LuckPaste() {
11+
}
1012

1113
public static String post(String content) {
1214
HttpURLConnection conn = null;
1315
try {
14-
URL url = new URL("Hastebin URL");
16+
URL url = URI.create("https://api.eztxm.de/v1/paste/add").toURL();
1517
conn = (HttpURLConnection) url.openConnection();
1618
conn.setConnectTimeout(4000);
1719
conn.setReadTimeout(6000);
18-
conn.setRequestMethod("POST");
20+
conn.setRequestMethod("PUT");
1921
conn.setDoOutput(true);
2022
conn.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
2123
try (OutputStream os = conn.getOutputStream()) {
2224
os.write(content.getBytes(StandardCharsets.UTF_8));
2325
}
2426
int code = conn.getResponseCode();
25-
if (code != 200 && code != 201) return null;
27+
if (code != 200 && code != 201)
28+
return null;
2629

2730
String resp;
2831
try (InputStream is = conn.getInputStream()) {
2932
resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
3033
}
3134

3235
int idx = resp.indexOf("\"key\"");
33-
if (idx < 0) return null;
36+
if (idx < 0)
37+
return null;
3438
int colon = resp.indexOf(':', idx);
3539
int quote1 = resp.indexOf('"', colon + 1);
3640
int quote2 = resp.indexOf('"', quote1 + 1);
37-
if (quote1 < 0 || quote2 < 0) return null;
41+
if (quote1 < 0 || quote2 < 0)
42+
return null;
3843
String key = resp.substring(quote1 + 1, quote2).trim();
39-
if (key.isEmpty()) return null;
40-
return "https://hastebin URL/" + key;
44+
if (key.isEmpty())
45+
return null;
46+
return "https://paste.eztxm.de/" + key;
4147
} catch (Exception ignored) {
4248
return null;
4349
} finally {
44-
if (conn != null) conn.disconnect();
50+
if (conn != null)
51+
conn.disconnect();
4552
}
4653
}
4754
}

luckprefix-common/src/main/java/de/eztxm/luckprefix/common/migrate/.placeholder

Whitespace-only changes.

luckprefix-common/src/main/java/de/eztxm/luckprefix/common/updater/.placeholder

Whitespace-only changes.

0 commit comments

Comments
 (0)