PlotSquared/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java

204 lines
9.7 KiB
Java
Raw Normal View History

/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* 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.
*
* 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.
*
* 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-15 21:26:54 +02:00
package com.plotsquared.core.command;
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;
import org.checkerframework.checker.nullness.qual.NonNull;
2020-07-14 18:49:40 +02:00
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.file.Files;
2019-12-27 16:53:38 +01:00
import java.util.concurrent.TimeUnit;
Pull/2693 (#2694) * Commit WIP flag work. * More ported flag types, and additions to the flag API. * Make PlotFlag more generic to allow generic flag creation * Pull Captions methods into a Caption interface. * Port MusicFlag * Port flight flag * Port UntrustedVisitFlag * Port DenyExitFlag * Remove paper suggestion * Make ListFlag lists immutable * Update Flag containers. Add javadocs. Add missing methods. * Port description flag * Port greeting and farewell flags * Port weather flag * Move getExample implementation to BooleanFlag * Port reserved flags * Port all boolean flags. * Remove unused flag types * Invert liquid-flow flag * Find the real (legacy) flag name * Change NOITFY -> NOTIFY in Captions * Make IntegerFlag extendable * Port integer flags * Update Flag command to current API state * Begin remaking flag command * Create DoubleFlag + extract common parsing stuff * Supply arguments in flag parse exceptions * Implement missing flag subcommands * Update Flag command to current API state * Implement PriceFlag * Port deny-teleport * Port gamemode flags * Port BreakFlag * Port PlaceFlag * Port UseFlag * Remove old unused flag constants * Port blocked-cmds flag * Fix entity util * Port TimeFlag * Use CaptionUtility for formatting * Port keep flag * Fix imports * Reformat code * Remove unused classes * Fix MainUtil.java * Remove FlagCmd * Add flag info header and footer * Comment out flag related stuff in SchematicHandler * Remove FlagManager * Finalize Plot.java * Finalize PlotArea.java * Finalize PlotListener * Fix API issues * Fix a bunch of compile errors * Fix `/plot flag remove` * Fix initialization of GlobalFlagContainer * Apply API changes to events * Update SQLManager to new API * Invert default value for DenyExitFlag * Replace flag.getValue().toString() with flag.toString() * Make FlagContainer instance in Plot final * Fix various command issues * Clean up PlotSettings * Don't show internal flags in flag list * Fix `/plot flag add` * Remove the info inventory as it's 100% broken * Add plot info entries and fix up the default format * Fix default flag state in Captions * 781c200 part 2 * Fix odd grammar in captions * Fix odd grammar in captions v2 * Add create table statements for plot_flags * Remove old flag references in SQLManager * Use the new plot_flags table * Add tab completion to `/plot flag` * Improve parse error handling * Make flag permission check recognize parse exceptions * Initial progress towards flag conversion * Fix minor issues * Don't validate flags during flag conversion * Allow unrecognized flags to be parsed * Filter out internal flags from command sugguestions * Use the wrong caption when there's no plot description set * Limit command suggestions for boolean flags * Make blocktypelistflags accept blockcategories * Require categories to be prefixed with '#' and fix some minor display issues * Fix plot database conversion * Update PlotFlagEvent.java Updated return description * Fix command annotation wrapping * Add FLAG_UPDATE event for FlagContainer listeners * Make getParentContainer nullable * Document castUnsafe in FlagContainer * Document FlagContainer constructors * Add missing documentation to FlagContainer * Document FlagParseException * Fix wording in FlagContainer javadoc * Document InternalFlag * Document PlotFlag * Minor changes * Remove revisit comments Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
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)
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;
@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;
}
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
TaskManager.runTaskAsync(() -> {
try {
StringBuilder b = new StringBuilder();
b.append(
"""
# 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");
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");
b.append("# WorldEdit implementation:\n");
b.append(PlotSquared.platform().worldEditImplementations()).append("\n\n");
b.append("# Server Information\n");
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');
b.append(PlotSquared.platform().pluginsFormatted());
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
Runtime runtime = Runtime.getRuntime();
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');
b.append("Java Name: ").append(rb.getVmName()).append('\n');
Pull/2693 (#2694) * Commit WIP flag work. * More ported flag types, and additions to the flag API. * Make PlotFlag more generic to allow generic flag creation * Pull Captions methods into a Caption interface. * Port MusicFlag * Port flight flag * Port UntrustedVisitFlag * Port DenyExitFlag * Remove paper suggestion * Make ListFlag lists immutable * Update Flag containers. Add javadocs. Add missing methods. * Port description flag * Port greeting and farewell flags * Port weather flag * Move getExample implementation to BooleanFlag * Port reserved flags * Port all boolean flags. * Remove unused flag types * Invert liquid-flow flag * Find the real (legacy) flag name * Change NOITFY -> NOTIFY in Captions * Make IntegerFlag extendable * Port integer flags * Update Flag command to current API state * Begin remaking flag command * Create DoubleFlag + extract common parsing stuff * Supply arguments in flag parse exceptions * Implement missing flag subcommands * Update Flag command to current API state * Implement PriceFlag * Port deny-teleport * Port gamemode flags * Port BreakFlag * Port PlaceFlag * Port UseFlag * Remove old unused flag constants * Port blocked-cmds flag * Fix entity util * Port TimeFlag * Use CaptionUtility for formatting * Port keep flag * Fix imports * Reformat code * Remove unused classes * Fix MainUtil.java * Remove FlagCmd * Add flag info header and footer * Comment out flag related stuff in SchematicHandler * Remove FlagManager * Finalize Plot.java * Finalize PlotArea.java * Finalize PlotListener * Fix API issues * Fix a bunch of compile errors * Fix `/plot flag remove` * Fix initialization of GlobalFlagContainer * Apply API changes to events * Update SQLManager to new API * Invert default value for DenyExitFlag * Replace flag.getValue().toString() with flag.toString() * Make FlagContainer instance in Plot final * Fix various command issues * Clean up PlotSettings * Don't show internal flags in flag list * Fix `/plot flag add` * Remove the info inventory as it's 100% broken * Add plot info entries and fix up the default format * Fix default flag state in Captions * 781c200 part 2 * Fix odd grammar in captions * Fix odd grammar in captions v2 * Add create table statements for plot_flags * Remove old flag references in SQLManager * Use the new plot_flags table * Add tab completion to `/plot flag` * Improve parse error handling * Make flag permission check recognize parse exceptions * Initial progress towards flag conversion * Fix minor issues * Don't validate flags during flag conversion * Allow unrecognized flags to be parsed * Filter out internal flags from command sugguestions * Use the wrong caption when there's no plot description set * Limit command suggestions for boolean flags * Make blocktypelistflags accept blockcategories * Require categories to be prefixed with '#' and fix some minor display issues * Fix plot database conversion * Update PlotFlagEvent.java Updated return description * Fix command annotation wrapping * Add FLAG_UPDATE event for FlagContainer listeners * Make getParentContainer nullable * Document castUnsafe in FlagContainer * Document FlagContainer constructors * Add missing documentation to FlagContainer * Document FlagParseException * Fix wording in FlagContainer javadoc * Document InternalFlag * Document PlotFlag * Minor changes * Remove revisit comments Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
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");
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');
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");
final IncendoPaster incendoPaster = new IncendoPaster("plotsquared");
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");
if (Files.size(logFile.toPath()) > 14_000_000) {
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);
} catch (IOException ignored) {
2020-08-17 18:15:29 +02:00
player.sendMessage(
TranslatableCaption.of("debugpaste.latest_log"),
Template.of("file", "latest.log"),
Template.of("size", "14MB")
);
}
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) {
player.sendMessage(
TranslatableCaption.of("debugpaste.empty_file"),
Template.of("file", "settings.yml")
);
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) {
player.sendMessage(
TranslatableCaption.of("debugpaste.empty_file"),
Template.of("file", "worlds.yml")
);
2019-01-10 21:34:52 +01:00
}
2019-10-01 12:12:42 +02:00
try {
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) {
player.sendMessage(
TranslatableCaption.of("debugpaste.skip_multiverse"),
Template.of("file", "worlds.yml")
);
2019-10-01 12:12:42 +02: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();
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);
player.sendMessage(
2020-07-22 00:08:51 +02:00
TranslatableCaption.of("debugpaste.debug_report_created"),
Template.of("url", link)
2020-07-22 00:08:51 +02:00
);
} else {
final String responseMessage = jsonObject.get("response").getAsString();
2020-07-22 00:08:51 +02:00
player.sendMessage(
TranslatableCaption.of("debugpaste.creation_failed"),
Template.of("value", responseMessage)
2020-07-22 00:08:51 +02:00
);
}
} catch (final Throwable throwable) {
throwable.printStackTrace();
2020-07-22 00:08:51 +02:00
player.sendMessage(
TranslatableCaption.of("debugpaste.creation_failed"),
Template.of("value", throwable.getMessage())
2020-07-22 00:08:51 +02:00
);
2018-12-27 17:29:35 +01:00
}
} catch (IOException e) {
e.printStackTrace();
}
});
return true;
}
2020-12-28 13:30:53 +01:00
}