2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program 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 General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.command;
|
2015-07-18 19:18:15 +02:00
|
|
|
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonParser;
|
2020-12-21 20:33:49 +01:00
|
|
|
import com.google.inject.Inject;
|
2020-12-19 17:00:13 +01:00
|
|
|
import com.intellectualsites.paster.IncendoPaster;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-12-22 17:55:37 +01:00
|
|
|
import com.plotsquared.core.configuration.Storage;
|
2020-07-22 00:08:51 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-07-17 17:24:45 +02:00
|
|
|
import com.plotsquared.core.inject.annotations.ConfigFile;
|
|
|
|
import com.plotsquared.core.inject.annotations.WorldFile;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.util.PremiumVerification;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.task.TaskManager;
|
2020-07-22 00:08:51 +02:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
2020-07-14 18:49:40 +02:00
|
|
|
|
2016-02-22 05:29:33 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2019-07-25 20:02:39 +02:00
|
|
|
import java.lang.management.ManagementFactory;
|
|
|
|
import java.lang.management.RuntimeMXBean;
|
2019-01-09 23:12:36 +01:00
|
|
|
import java.nio.file.Files;
|
2019-12-27 16:53:38 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2016-02-22 05:29:33 +01:00
|
|
|
|
2020-02-24 18:42:02 +01:00
|
|
|
@CommandDeclaration(command = "debugpaste",
|
2020-12-21 20:33:49 +01:00
|
|
|
aliases = "dp",
|
|
|
|
usage = "/plot debugpaste",
|
|
|
|
permission = "plots.debugpaste",
|
|
|
|
category = CommandCategory.DEBUG,
|
|
|
|
confirmation = true,
|
|
|
|
requiredType = RequiredType.NONE)
|
2019-10-03 01:12:08 +02:00
|
|
|
public class DebugPaste extends SubCommand {
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2020-12-21 20:33:49 +01:00
|
|
|
private final File configFile;
|
|
|
|
private final File worldfile;
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Inject
|
|
|
|
public DebugPaste(
|
|
|
|
@ConfigFile final @NonNull File configFile,
|
|
|
|
@WorldFile final @NonNull File worldFile
|
|
|
|
) {
|
2020-12-21 20:33:49 +01:00
|
|
|
this.configFile = configFile;
|
|
|
|
this.worldfile = worldFile;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
2019-01-09 23:12:36 +01:00
|
|
|
TaskManager.runTaskAsync(() -> {
|
|
|
|
try {
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
b.append(
|
2022-01-12 22:21:51 +01:00
|
|
|
"""
|
|
|
|
# Welcome to this paste
|
|
|
|
# It is meant to provide us at IntellectualSites with better information about your problem
|
|
|
|
"""
|
|
|
|
);
|
2020-02-19 23:55:43 +01:00
|
|
|
b.append("# PlotSquared Information\n");
|
2020-05-13 14:13:14 +02:00
|
|
|
b.append("PlotSquared Version: ").append(PlotSquared.get().getVersion())
|
2020-12-21 20:33:49 +01:00
|
|
|
.append("\n");
|
2020-12-22 17:55:37 +01:00
|
|
|
b.append("Database Type: ").append(Storage.MySQL.USE ? "MySQL" : "SQLite").append("\n");
|
2020-04-21 23:38:56 +02:00
|
|
|
b.append("Resource ID: ").append(PremiumVerification.getResourceID()).append("\n");
|
|
|
|
b.append("Download ID: ").append(PremiumVerification.getDownloadID()).append("\n");
|
2020-04-30 12:33:59 +02:00
|
|
|
b.append("This PlotSquared version is licensed to the spigot user ")
|
2020-12-21 20:33:49 +01:00
|
|
|
.append(PremiumVerification.getUserID()).append("\n\n");
|
2022-01-12 22:21:51 +01:00
|
|
|
b.append("# WorldEdit implementation:\n");
|
|
|
|
b.append(PlotSquared.platform().worldEditImplementations()).append("\n\n");
|
2019-01-09 23:12:36 +01:00
|
|
|
b.append("# Server Information\n");
|
2020-12-05 18:41:25 +01:00
|
|
|
b.append("Server Version: ").append(PlotSquared.platform().serverImplementation())
|
2020-12-21 20:33:49 +01:00
|
|
|
.append("\n");
|
2020-05-19 23:05:36 +02:00
|
|
|
b.append("online_mode: ").append(!Settings.UUID.OFFLINE).append(';')
|
2020-12-21 20:33:49 +01:00
|
|
|
.append(!Settings.UUID.OFFLINE).append('\n');
|
2020-12-05 18:41:25 +01:00
|
|
|
b.append(PlotSquared.platform().pluginsFormatted());
|
2019-01-09 23:12:36 +01:00
|
|
|
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
|
|
|
|
Runtime runtime = Runtime.getRuntime();
|
2019-07-25 20:02:39 +02:00
|
|
|
RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
|
2020-10-04 18:19:29 +02:00
|
|
|
b.append("Uptime: ")
|
2020-12-21 20:33:49 +01:00
|
|
|
.append(TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS))
|
|
|
|
.append(" minutes")
|
|
|
|
.append('\n');
|
2019-12-27 16:53:38 +01:00
|
|
|
b.append("JVM Flags: ").append(rb.getInputArguments()).append('\n');
|
2020-10-04 18:19:29 +02:00
|
|
|
b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024).append(" MB")
|
2020-12-21 20:33:49 +01:00
|
|
|
.append('\n');
|
2020-10-04 18:19:29 +02:00
|
|
|
b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024).append(" MB")
|
2020-12-21 20:33:49 +01:00
|
|
|
.append('\n');
|
2020-10-04 18:19:29 +02:00
|
|
|
b.append("Total Memory: ").append(runtime.totalMemory() / 1024 / 1024).append(" MB")
|
2020-12-21 20:33:49 +01:00
|
|
|
.append('\n');
|
2020-07-31 20:33:17 +02:00
|
|
|
b.append("Available Processors: ").append(runtime.availableProcessors()).append('\n');
|
2019-07-25 20:02:39 +02:00
|
|
|
b.append("Java Name: ").append(rb.getVmName()).append('\n');
|
2020-02-24 18:42:02 +01:00
|
|
|
b.append("Java Version: '").append(System.getProperty("java.version"))
|
2020-12-21 20:33:49 +01:00
|
|
|
.append("'\n");
|
2019-07-25 20:02:39 +02:00
|
|
|
b.append("Java Vendor: '").append(System.getProperty("java.vendor")).append("'\n");
|
|
|
|
b.append("Operating System: '").append(System.getProperty("os.name")).append("'\n");
|
|
|
|
b.append("OS Version: ").append(System.getProperty("os.version")).append('\n');
|
|
|
|
b.append("OS Arch: ").append(System.getProperty("os.arch")).append('\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(
|
2021-04-28 20:17:10 +02:00
|
|
|
"\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
|
2021-02-17 00:50:50 +01:00
|
|
|
b.append("\n# or via our Discord at https://discord.gg/intellectualsites");
|
2019-01-09 23:12:36 +01:00
|
|
|
|
2019-05-14 03:57:41 +02:00
|
|
|
final IncendoPaster incendoPaster = new IncendoPaster("plotsquared");
|
2019-01-09 23:12:36 +01:00
|
|
|
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 =
|
2021-04-28 20:17:10 +02:00
|
|
|
new File("logs/latest.log");
|
2019-01-09 23:12:36 +01:00
|
|
|
if (Files.size(logFile.toPath()) > 14_000_000) {
|
2021-01-09 22:28:41 +01:00
|
|
|
throw new IOException(
|
|
|
|
"The latest.log is larger than 14MB. Please reboot your server and submit a new paste.");
|
2018-12-27 17:29:35 +01:00
|
|
|
}
|
2020-12-21 20:33:49 +01:00
|
|
|
incendoPaster
|
|
|
|
.addFile(logFile);
|
2019-01-09 23:12:36 +01:00
|
|
|
} catch (IOException ignored) {
|
2020-08-17 18:15:29 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugpaste.latest_log"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("file", "latest.log"),
|
|
|
|
Template.of("size", "14MB")
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
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 {
|
2020-12-21 20:33:49 +01:00
|
|
|
incendoPaster.addFile(this.configFile);
|
2019-01-10 21:34:52 +01:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
2021-01-09 22:28:41 +01:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugpaste.empty_file"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("file", "settings.yml")
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2019-01-10 21:34:52 +01:00
|
|
|
}
|
2020-12-21 20:33:49 +01:00
|
|
|
try {
|
|
|
|
incendoPaster.addFile(this.worldfile);
|
2019-01-10 21:34:52 +01:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
2021-01-09 22:28:41 +01:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugpaste.empty_file"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("file", "worlds.yml")
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2019-01-10 21:34:52 +01:00
|
|
|
}
|
|
|
|
|
2019-10-01 12:12:42 +02:00
|
|
|
try {
|
2021-01-09 22:28:41 +01:00
|
|
|
final File MultiverseWorlds = new File(
|
|
|
|
PlotSquared.platform().getDirectory(),
|
|
|
|
"../Multiverse-Core/worlds.yml"
|
|
|
|
);
|
2020-12-28 13:30:53 +01:00
|
|
|
incendoPaster.addFile(MultiverseWorlds, "Multiverse-Core/worlds.yml");
|
2019-10-01 12:12:42 +02:00
|
|
|
} catch (final IOException ignored) {
|
2021-01-09 22:28:41 +01:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugpaste.skip_multiverse"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("file", "worlds.yml")
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2019-10-01 12:12:42 +02: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 =
|
2020-12-21 20:33:49 +01:00
|
|
|
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 =
|
2020-12-21 20:33:49 +01:00
|
|
|
String.format("https://athion.net/ISPaster/paste/view/%s", pasteId);
|
2019-08-07 02:35:36 +02:00
|
|
|
player.sendMessage(
|
2020-07-22 00:08:51 +02:00
|
|
|
TranslatableCaption.of("debugpaste.debug_report_created"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("url", link)
|
2020-07-22 00:08:51 +02:00
|
|
|
);
|
2019-01-09 23:12:36 +01:00
|
|
|
} else {
|
|
|
|
final String responseMessage = jsonObject.get("response").getAsString();
|
2020-07-22 00:08:51 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugpaste.creation_failed"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("value", responseMessage)
|
2020-07-22 00:08:51 +02:00
|
|
|
);
|
2019-01-09 23:12:36 +01:00
|
|
|
}
|
|
|
|
} catch (final Throwable throwable) {
|
|
|
|
throwable.printStackTrace();
|
2020-07-22 00:08:51 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugpaste.creation_failed"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("value", throwable.getMessage())
|
2020-07-22 00:08:51 +02:00
|
|
|
);
|
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;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2020-12-28 13:30:53 +01:00
|
|
|
}
|