paste.gg and mclo.gs default

This commit is contained in:
zax71 2023-08-28 16:45:57 +01:00
parent 5af06d9a0f
commit fa81f5b573
1 changed files with 33 additions and 17 deletions

View File

@ -44,6 +44,7 @@ public class DumpsCommand extends MultiverseCommand {
private final MVCoreConfig config;
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private boolean hasArgs = false;
@Inject
public DumpsCommand(@NotNull MVCommandManager commandManager,
@ -103,7 +104,6 @@ public class DumpsCommand extends MultiverseCommand {
@Override
public void run() {
HashMap<String, String> pasteURLs = new HashMap<>();
boolean hasArgs = false;
if (parsedFlags.hasFlag("--pastebincom")) {
hasArgs = true;
@ -120,28 +120,23 @@ public class DumpsCommand extends MultiverseCommand {
if (parsedFlags.hasFlag("--logs")) {
hasArgs = true;
issuer.sendInfo(MVCorei18n.DUMPS_UPLOADING_LOGS, "{link}", "https://mclo.gs");
// Get the Path of latest.log
Path logsPath = plugin.getServer().getWorldContainer().toPath().resolve("logs").resolve("latest.log");
String logs;
// Try to read file
try {
logs = Files.readString(logsPath);
} catch (IOException e) {
Logging.warning("Could not read logs/latest.log");
throw new RuntimeException(e);
}
pasteURLs.put("Logs", postToService(PasteServiceType.MCLOGS, false, logs, null));
pasteURLs.putAll(uploadLogs());
}
// Fallback to paste.gg if no other sites where specified
if (parsedFlags.hasFlag("--pastegg") || !hasArgs) {
if (parsedFlags.hasFlag("--pastegg")) {
issuer.sendInfo(MVCorei18n.DUMPS_UPLOADING, "{link}", "https://paste.gg");
pasteURLs.put("paste.gg", postToService(PasteServiceType.PASTEGG, true, null, files));
}
// Fallback to paste.gg and logs if no other sites where specified
if (!hasArgs) {
issuer.sendInfo(MVCorei18n.DUMPS_UPLOADING, "{link}", "https://paste.gg");
pasteURLs.put("paste.gg", postToService(PasteServiceType.PASTEGG, true, null, files));
issuer.sendInfo(MVCorei18n.DUMPS_UPLOADING_LOGS, "{link}", "https://mclo.gs");
pasteURLs.putAll(uploadLogs());
}
// Finally, loop through and print all URLs
for (String service : pasteURLs.keySet()) {
String link = pasteURLs.get(service);
@ -155,6 +150,27 @@ public class DumpsCommand extends MultiverseCommand {
logPoster.runTaskAsynchronously(plugin);
}
private HashMap<String, String> uploadLogs() {
HashMap<String, String> outMap = new HashMap<>();
// Get the Path of latest.log
Path logsPath = plugin.getServer().getWorldContainer().toPath().resolve("logs").resolve("latest.log");
String logs;
// Try to read file
try {
logs = Files.readString(logsPath);
} catch (IOException e) {
Logging.warning("Could not read logs/latest.log");
throw new RuntimeException(e);
}
outMap.put("Logs", postToService(PasteServiceType.MCLOGS, false, logs, null));
return outMap;
}
private String getVersionString() {
return "# Multiverse-Core Version info" + "\n\n"
+ " - Multiverse-Core Version: " + this.plugin.getDescription().getVersion() + '\n'