2018-08-10 17:53:14 +02:00
|
|
|
package com.github.intellectualsites.plotsquared.plot.commands;
|
2015-07-18 19:18:15 +02:00
|
|
|
|
2018-08-10 17:53:14 +02:00
|
|
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
2018-11-14 14:19:56 +01:00
|
|
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
2018-08-10 17:53:14 +02:00
|
|
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
|
|
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
|
|
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
2019-01-09 23:12:36 +01:00
|
|
|
import com.github.intellectualsites.plotsquared.plot.util.IncendoPaster;
|
2018-08-10 17:53:14 +02:00
|
|
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
|
|
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
|
|
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
2019-01-09 23:12:36 +01:00
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
import lombok.NonNull;
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2019-01-09 23:12:36 +01:00
|
|
|
import java.io.BufferedReader;
|
2016-02-22 05:29:33 +01:00
|
|
|
import java.io.File;
|
2019-01-09 23:12:36 +01:00
|
|
|
import java.io.FileReader;
|
2016-02-22 05:29:33 +01:00
|
|
|
import java.io.IOException;
|
2019-01-09 23:12:36 +01:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.util.List;
|
2019-02-08 20:49:37 +01:00
|
|
|
import java.util.stream.Collectors;
|
2016-02-22 05:29:33 +01:00
|
|
|
|
2018-12-26 18:21:06 +01:00
|
|
|
@CommandDeclaration(command = "debugpaste", aliases = "dp", usage = "/plot debugpaste",
|
2019-01-09 23:40:08 +01:00
|
|
|
description = "Upload settings.yml, worlds.yml, PlotSquared.use_THIS.yml and your latest.log to https://incendo.org",
|
2018-12-26 18:21:06 +01:00
|
|
|
permission = "plots.debugpaste", category = CommandCategory.DEBUG) public class DebugPaste
|
|
|
|
extends SubCommand {
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2019-02-04 14:59:11 +01:00
|
|
|
private static String readFile(@NonNull final File file) throws IOException {
|
|
|
|
final StringBuilder content = new StringBuilder();
|
2019-02-08 20:49:37 +01:00
|
|
|
final List<String> lines;
|
2019-02-04 14:59:11 +01:00
|
|
|
try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
2019-02-08 20:49:37 +01:00
|
|
|
lines = reader.lines().collect(Collectors.toList());
|
2019-02-04 14:59:11 +01:00
|
|
|
}
|
|
|
|
for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) {
|
|
|
|
content.append(lines.get(i)).append("\n");
|
|
|
|
}
|
|
|
|
return content.toString();
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
2019-01-09 23:12:36 +01:00
|
|
|
TaskManager.runTaskAsync(() -> {
|
|
|
|
try {
|
|
|
|
final IncendoPaster incendoPaster = new IncendoPaster("plotsquared");
|
|
|
|
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
b.append(
|
|
|
|
"# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your "
|
|
|
|
+ "problem\n\n");
|
|
|
|
b.append("# Server Information\n");
|
2019-02-04 14:59:11 +01:00
|
|
|
b.append("server.version: ").append(PlotSquared.get().IMP.getServerImplementation())
|
|
|
|
.append("\n");
|
2019-01-09 23:12:36 +01:00
|
|
|
b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';')
|
|
|
|
.append(!Settings.UUID.OFFLINE).append('\n');
|
|
|
|
b.append("plugins:");
|
|
|
|
for (String id : PlotSquared.get().IMP.getPluginIds()) {
|
|
|
|
String[] split = id.split(":");
|
|
|
|
String[] split2 = split[0].split(";");
|
|
|
|
String enabled = split.length == 2 ? split[1] : "unknown";
|
|
|
|
String name = split2[0];
|
|
|
|
String version = split2.length == 2 ? split2[1] : "unknown";
|
|
|
|
b.append("\n ").append(name).append(":\n ").append("version: '")
|
|
|
|
.append(version).append('\'').append("\n enabled: ").append(enabled);
|
|
|
|
}
|
|
|
|
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
|
|
|
|
Runtime runtime = Runtime.getRuntime();
|
|
|
|
b.append("memory.free: ").append(runtime.freeMemory()).append('\n');
|
|
|
|
b.append("memory.max: ").append(runtime.maxMemory()).append('\n');
|
|
|
|
b.append("java.specification.version: '")
|
|
|
|
.append(System.getProperty("java.specification.version")).append("'\n");
|
2019-02-04 14:59:11 +01:00
|
|
|
b.append("java.vendor: '").append(System.getProperty("java.vendor")).append("'\n");
|
2019-01-09 23:12:36 +01:00
|
|
|
b.append("java.version: '").append(System.getProperty("java.version"))
|
|
|
|
.append("'\n");
|
|
|
|
b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n");
|
|
|
|
b.append("os.name: '").append(System.getProperty("os.name")).append("'\n");
|
2019-02-04 14:59:11 +01:00
|
|
|
b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n");
|
2019-01-09 23:12:36 +01:00
|
|
|
b.append("# Okay :D Great. You are now ready to create your bug report!");
|
|
|
|
b.append(
|
|
|
|
"\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
|
|
|
|
b.append("\n# or via our Discord at https://discord.gg/ngZCzbU");
|
|
|
|
|
|
|
|
incendoPaster.addFile(new IncendoPaster.PasteFile("information", b.toString()));
|
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
try {
|
2019-02-04 14:59:11 +01:00
|
|
|
final File logFile =
|
|
|
|
new File(PlotSquared.get().IMP.getDirectory(), "../../logs/latest.log");
|
2019-01-09 23:12:36 +01:00
|
|
|
if (Files.size(logFile.toPath()) > 14_000_000) {
|
|
|
|
throw new IOException("Too big...");
|
2018-12-27 17:29:35 +01:00
|
|
|
}
|
2019-02-04 14:59:11 +01:00
|
|
|
incendoPaster
|
|
|
|
.addFile(new IncendoPaster.PasteFile("latest.log", readFile(logFile)));
|
2019-01-09 23:12:36 +01:00
|
|
|
} catch (IOException ignored) {
|
2019-02-04 14:59:11 +01:00
|
|
|
MainUtil
|
|
|
|
.sendMessage(player, "&clatest.log is too big to be pasted, will ignore");
|
2019-01-09 23:12:36 +01:00
|
|
|
}
|
2018-12-26 22:18:22 +01:00
|
|
|
|
2019-01-10 21:34:52 +01:00
|
|
|
try {
|
2019-02-04 14:59:11 +01:00
|
|
|
incendoPaster.addFile(new IncendoPaster.PasteFile("settings.yml",
|
|
|
|
readFile(PlotSquared.get().configFile)));
|
2019-01-10 21:34:52 +01:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
|
|
|
MainUtil.sendMessage(player, "&cSkipping settings.yml because it's empty");
|
|
|
|
}
|
|
|
|
try {
|
2019-02-04 14:59:11 +01:00
|
|
|
incendoPaster.addFile(new IncendoPaster.PasteFile("worlds.yml",
|
|
|
|
readFile(PlotSquared.get().worldsFile)));
|
2019-01-10 21:34:52 +01:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
|
|
|
MainUtil.sendMessage(player, "&cSkipping worlds.yml because it's empty");
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
incendoPaster.addFile(new IncendoPaster.PasteFile("PlotSquared.use_THIS.yml",
|
|
|
|
readFile(PlotSquared.get().translationFile)));
|
|
|
|
} catch (final IllegalArgumentException ignored) {
|
2019-02-04 14:59:11 +01:00
|
|
|
MainUtil.sendMessage(player,
|
|
|
|
"&cSkipping PlotSquared.use_THIS.yml because it's empty");
|
2019-01-10 21:34:52 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 23:12:36 +01:00
|
|
|
try {
|
|
|
|
final String rawResponse = incendoPaster.upload();
|
2019-02-04 14:59:11 +01:00
|
|
|
final JsonObject jsonObject =
|
|
|
|
new JsonParser().parse(rawResponse).getAsJsonObject();
|
2019-01-09 23:12:36 +01:00
|
|
|
|
|
|
|
if (jsonObject.has("created")) {
|
|
|
|
final String pasteId = jsonObject.get("paste_id").getAsString();
|
2019-02-04 14:59:11 +01:00
|
|
|
final String link =
|
|
|
|
String.format("https://incendo.org/paste/view/%s", pasteId);
|
|
|
|
player.sendMessage(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
|
2019-01-09 23:12:36 +01:00
|
|
|
} else {
|
|
|
|
final String responseMessage = jsonObject.get("response").getAsString();
|
2019-02-04 14:59:11 +01:00
|
|
|
MainUtil.sendMessage(player, String
|
|
|
|
.format("&cFailed to create the debug paste: %s", responseMessage));
|
2019-01-09 23:12:36 +01:00
|
|
|
}
|
|
|
|
} catch (final Throwable throwable) {
|
|
|
|
throwable.printStackTrace();
|
2019-02-04 14:59:11 +01:00
|
|
|
MainUtil.sendMessage(player,
|
|
|
|
"&cFailed to create the debug paste: " + throwable.getMessage());
|
2018-12-27 17:29:35 +01:00
|
|
|
}
|
2019-01-09 23:12:36 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2015-07-18 19:18:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|