diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index ba4943366..638c1988a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -99,11 +99,11 @@ public enum Message { */ VERBOSE_INVALID_FILTER("&cInvalid verbose filter: &f{0}", true), VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true), - VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}", true), + VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching filter: &f{0}", true), VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true), VERBOSE_RECORDING_ON("&bVerbose recording set to &aTRUE &bfor all permissions.", true), - VERBOSE_RECORDING_ON_QUERY("&bVerbose recording set to &aTRUE &bfor permissions matching the following filters: &f{0}", true), + VERBOSE_RECORDING_ON_QUERY("&bVerbose recording set to &aTRUE &bfor permissions matching filter: &f{0}", true), VERBOSE_RECORDING_UPLOAD_START("&bVerbose recording was disabled. Uploading results...", true), VERBOSE_RECORDING_URL("&aVerbose results URL:", true), diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/PasteUtils.java b/common/src/main/java/me/lucko/luckperms/common/utils/PasteUtils.java index 10c424c07..c60465192 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/PasteUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/PasteUtils.java @@ -26,6 +26,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.stream.JsonWriter; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.StringWriter; @@ -36,8 +37,9 @@ import java.nio.charset.StandardCharsets; public class PasteUtils { public static String paste(String name, String desc, String contents) { + HttpURLConnection connection = null; try { - HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/gists").openConnection(); + connection = (HttpURLConnection) new URL("https://api.github.com/gists").openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); @@ -58,11 +60,17 @@ public class PasteUtils { } if (connection.getResponseCode() >= 400) { - return null; + throw new RuntimeException("Connection returned response code: " + connection.getResponseCode() + " - " + connection.getResponseMessage()); + } + + String pasteUrl; + try (InputStream inputStream = connection.getInputStream()) { + try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { + JsonObject response = new Gson().fromJson(reader, JsonObject.class); + pasteUrl = response.get("html_url").getAsString(); + } } - JsonObject response = new Gson().fromJson(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8), JsonObject.class); - String pasteUrl = response.get("html_url").getAsString(); connection.disconnect(); try { @@ -72,15 +80,31 @@ public class PasteUtils { try (OutputStream os = connection.getOutputStream()) { os.write(("url=" + pasteUrl).getBytes(StandardCharsets.UTF_8)); } - pasteUrl = connection.getHeaderField("Location"); - connection.disconnect(); + + if (connection.getResponseCode() >= 400) { + new RuntimeException("Connection returned response code: " + connection.getResponseCode() + " - " + connection.getResponseMessage()).printStackTrace(); + } else { + String shortUrl = connection.getHeaderField("Location"); + if (shortUrl != null) { + pasteUrl = shortUrl; + } + } } catch (Exception e) { - // ignored + e.printStackTrace(); } return pasteUrl; } catch (Exception e) { + e.printStackTrace(); return null; + } finally { + if (connection != null) { + try { + connection.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } + } } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java index 818dd401e..9c7f3015e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java @@ -44,7 +44,7 @@ import javax.script.ScriptEngine; @RequiredArgsConstructor public class VerboseListener { - private static final int DATA_TRUNCATION = 700; + private static final int DATA_TRUNCATION = 3500; private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); private final long startTime = System.currentTimeMillis();