aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLulonaut <lulonaut@tutanota.de>2023-04-04 20:14:59 +0200
committerGitHub <noreply@github.com>2023-04-04 20:14:59 +0200
commit2c38bbcd4ab32709a0b300e4a2000c2dd9c2ca9d (patch)
treecc6e79deb1ffa1241a71cfb9dcc089b7f345f03a /src
parenta01bce903164749a0574210d1e6958ecd4090a5c (diff)
downloadNotEnoughUpdates-2c38bbcd4ab32709a0b300e4a2000c2dd9c2ca9d.tar.gz
NotEnoughUpdates-2c38bbcd4ab32709a0b300e4a2000c2dd9c2ca9d.tar.bz2
NotEnoughUpdates-2c38bbcd4ab32709a0b300e4a2000c2dd9c2ca9d.zip
Copy /neustats dump data to clipboard (#660)
This is needed because the generated data was too long for https://hst.sh/ Also adds a "copyToClipboard" extension function for String The HastebinUploader.java class is now no longer needed
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/HastebinUploader.java84
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt40
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt4
3 files changed, 17 insertions, 111 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HastebinUploader.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HastebinUploader.java
deleted file mode 100644
index 27993510..00000000
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/HastebinUploader.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2022 NotEnoughUpdates contributors
- *
- * This file is part of NotEnoughUpdates.
- *
- * NotEnoughUpdates is free software: you can redistribute it
- * and/or modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * NotEnoughUpdates is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package io.github.moulberry.notenoughupdates.util;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import org.apache.commons.io.Charsets;
-import org.apache.commons.io.IOUtils;
-
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-
-/**
- * @author ThatGravyBoat
- */
-public class HastebinUploader {
- private static final String UPLOAD_URL = "https://hst.sh/documents";
- private static final String RETURN_URL = "https://hst.sh/";
- private static final String RAW_RETURN_URL = "https://hst.sh/raw/";
-
- private static final Gson GSON = new Gson();
-
- /**
- * @param data the data you want to upload
- * @param mode the mode in which the thing should return NORMAL = returns the url, RAW = returns the raw url, NO_URL = returns the slug.
- * @return The url if mode is NORMAL OR RAW, the slug if mode is NO_URL, and null if an error occurred.
- */
- public static String upload(String data, Mode mode) {
- try {
- byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
- HttpURLConnection connection = (HttpURLConnection) new URL(UPLOAD_URL).openConnection();
- connection.setRequestMethod("POST");
- connection.addRequestProperty(
- "User-Agent",
- "Minecraft Mod (" + NotEnoughUpdates.MODID + "/" + NotEnoughUpdates.VERSION + ")"
- );
- connection.addRequestProperty("Content-Length", String.valueOf(bytes.length));
- connection.setReadTimeout(15000);
- connection.setConnectTimeout(15000);
- connection.setDoOutput(true);
- connection.getOutputStream().write(bytes);
- final JsonObject json =
- GSON.fromJson(IOUtils.toString(connection.getInputStream(), Charsets.UTF_8), JsonObject.class);
- if (!json.has("key")) return null;
- final String key = json.get("key").getAsString();
- switch (mode) {
- case RAW:
- return RAW_RETURN_URL + key;
- case NORMAL:
- return RETURN_URL + key;
- case NO_URL:
- return key;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public enum Mode {
- NORMAL,
- RAW,
- NO_URL
- }
-}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
index 7035aaa3..08869032 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
@@ -26,12 +26,12 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.util.DiscordMarkdownBuilder
-import io.github.moulberry.notenoughupdates.util.HastebinUploader
import io.github.moulberry.notenoughupdates.util.SBInfo
import io.github.moulberry.notenoughupdates.util.brigadier.reply
import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
import io.github.moulberry.notenoughupdates.util.brigadier.thenLiteralExecute
import io.github.moulberry.notenoughupdates.util.brigadier.withHelp
+import io.github.moulberry.notenoughupdates.util.copyToClipboard
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.command.ICommandSender
@@ -46,7 +46,6 @@ import org.lwjgl.opengl.GL11
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.lang.management.ManagementFactory
-import java.util.concurrent.CompletableFuture
import javax.management.JMX
import javax.management.ObjectName
@@ -71,10 +70,8 @@ class NEUStatsCommand {
)
}.withHelp("Copy the full list of all NEU stats and your mod list to your clipboard")
thenLiteralExecute("dump") {
- reply("${GREEN}This will upload a dump of the java classes your game has loaded how big they are and how many there are. This can take a few seconds as it is uploading to HasteBin.")
- uploadDataUsageDump().thenAccept {
- clipboardAndSendMessage(it)
- }
+ reply("${GREEN}This will copy a summary of the loaded Java classes to your clipboard. Please paste this into your discord support ticket by pressing CTRL+V.")
+ generateDataUsage().copyToClipboard()
}.withHelp("Dump all loaded classes and their memory usage and copy that to your clipboard.")
thenExecute {
clipboardAndSendMessage(
@@ -88,31 +85,20 @@ class NEUStatsCommand {
}
}.withHelp("Copy a list of NEU relevant stats to your clipboard for debugging purposes")
}
+
interface DiagnosticCommandMXBean {
fun gcClassHistogram(array: Array<String>): String
}
- private fun uploadDataUsageDump(): CompletableFuture<String?> {
- return CompletableFuture.supplyAsync {
- try {
- val server =
- ManagementFactory.getPlatformMBeanServer()
- val objectName =
- ObjectName.getInstance("com.sun.management:type=DiagnosticCommand")
- val proxy = JMX.newMXBeanProxy(
- server,
- objectName,
- DiagnosticCommandMXBean::class.java
- )
- HastebinUploader.upload(
- proxy.gcClassHistogram(emptyArray()).replace("[", "[]"),
- HastebinUploader.Mode.NORMAL
- )
- } catch (e: Exception) {
- null
- }
- }
-
+ private fun generateDataUsage(): String {
+ val server = ManagementFactory.getPlatformMBeanServer()
+ val objectName = ObjectName.getInstance("com.sun.management:type=DiagnosticCommand")
+ val proxy = JMX.newMXBeanProxy(
+ server,
+ objectName,
+ DiagnosticCommandMXBean::class.java
+ )
+ return proxy.gcClassHistogram(emptyArray()).replace("[", "[]")
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt
index dc1e800c..d8491167 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/KotlinStringUtils.kt
@@ -20,5 +20,9 @@
package io.github.moulberry.notenoughupdates.util
import net.minecraft.util.StringUtils
+import java.awt.Toolkit
+import java.awt.datatransfer.StringSelection
fun String.stripControlCodes(): String = StringUtils.stripControlCodes(this)
+
+fun String.copyToClipboard() = Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(this), null)