mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-10 09:31:51 +01:00
Implement /mv dumps command
This commit is contained in:
parent
bd78b441ba
commit
260777303c
@ -7,14 +7,6 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.anchor.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
@ -47,6 +39,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The implementation of the Multiverse-{@link MVCore}.
|
||||
*/
|
||||
@ -332,6 +330,34 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
return authors.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public File getBukkitConfig() {
|
||||
// Look in the default position
|
||||
File[] files = this.getServer().getWorldContainer().listFiles((file, s) -> s.equalsIgnoreCase("bukkit.yml"));
|
||||
|
||||
if (files != null && files.length == 1) {
|
||||
return files[0];
|
||||
}
|
||||
|
||||
// TODO: Implement binary search to find file, config option or use reflections to get it from configuration on CraftServer
|
||||
Logging.warning("Could not read bukkit.yml");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public File getServerProperties() {
|
||||
// Look in the default position
|
||||
File[] files = this.getServer().getWorldContainer().listFiles((file, s) -> s.equalsIgnoreCase("server.properties"));
|
||||
|
||||
if (files != null && files.length == 1) {
|
||||
return files[0];
|
||||
}
|
||||
|
||||
// TODO: Implement binary search to find file, config option or use reflections to get it from configuration on CraftServer
|
||||
Logging.warning("Could not read 'server.properties");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -377,7 +403,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
* Gets the best service from this plugin that implements the given contract or has the given implementation.
|
||||
*
|
||||
* @param contractOrImpl The contract or concrete implementation to get the best instance of
|
||||
* @param qualifiers The set of qualifiers that must match this service definition
|
||||
* @param qualifiers The set of qualifiers that must match this service definition
|
||||
* @return An instance of the contract or impl if it is a service and is already instantiated, null otherwise
|
||||
* @throws MultiException if there was an error during service lookup
|
||||
*/
|
||||
@ -395,7 +421,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
* the provided qualifiers.
|
||||
*
|
||||
* @param contractOrImpl The contract or concrete implementation to get the best instance of
|
||||
* @param qualifiers The set of qualifiers that must match this service definition
|
||||
* @param qualifiers The set of qualifiers that must match this service definition
|
||||
* @return A list of services implementing this contract or concrete implementation. May not return null, but may
|
||||
* return an empty list
|
||||
* @throws MultiException if there was an error during service lookup
|
||||
@ -415,10 +441,10 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
/**
|
||||
* This is for unit testing ONLY. Do not use this constructor.
|
||||
*
|
||||
* @param loader The PluginLoader to use.
|
||||
* @param loader The PluginLoader to use.
|
||||
* @param description The Description file to use.
|
||||
* @param dataFolder The folder that other datafiles can be found in.
|
||||
* @param file The location of the plugin.
|
||||
* @param dataFolder The folder that other datafiles can be found in.
|
||||
* @param file The location of the plugin.
|
||||
*/
|
||||
public MultiverseCore(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||
super(loader, description, dataFolder, file);
|
||||
|
@ -0,0 +1,242 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlag;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flags.ParsedCommandFlags;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import jakarta.inject.Inject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@CommandAlias("mv")
|
||||
public class DumpsCommand extends MultiverseCommand {
|
||||
|
||||
private final MVCoreConfig config;
|
||||
private final MultiverseCore plugin;
|
||||
private final MVWorldManager worldManager;
|
||||
|
||||
@Inject
|
||||
public DumpsCommand(@NotNull MVCommandManager commandManager,
|
||||
@NotNull MultiverseCore plugin,
|
||||
@NotNull MVCoreConfig config,
|
||||
@NotNull MVWorldManager worldManager) {
|
||||
super(commandManager);
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
this.worldManager = worldManager;
|
||||
|
||||
registerFlagGroup(CommandFlagGroup.builder("mvdumps")
|
||||
.add(CommandFlag.builder("--pastebincom")
|
||||
.addAlias("-b")
|
||||
.build())
|
||||
.add(CommandFlag.builder("--github")
|
||||
.addAlias("-g")
|
||||
.build())
|
||||
.add(CommandFlag.builder("--hastebin")
|
||||
.addAlias("-h")
|
||||
.build())
|
||||
.add(CommandFlag.builder("--pastegg")
|
||||
.addAlias("-p")
|
||||
.build())
|
||||
.add(CommandFlag.builder("--logs")
|
||||
.addAlias("-l")
|
||||
.build())
|
||||
.add(CommandFlag.builder("--include-plugin-list")
|
||||
.addAlias("-l")
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Subcommand("dumps")
|
||||
@CommandPermission("multiverse.core.dumps")
|
||||
@CommandCompletion("@flags:groupName=mvdumps")
|
||||
@Syntax("--pastebincom --hastebin --pastegg --logs --include-plugin-list")
|
||||
@Description("{@@mv-core.dumps.description}")
|
||||
public void onDumpsCommand(CommandIssuer issuer,
|
||||
|
||||
@Optional
|
||||
@Syntax("--pastebincom --hastebin --pastegg --logs --include-plugin-list")
|
||||
@Description("{@@mv-core.dumps.flags.description}")
|
||||
String[] flags
|
||||
) {
|
||||
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
||||
|
||||
MVVersionEvent versionEvent = new MVVersionEvent();
|
||||
|
||||
this.addDebugInfoToEvent(versionEvent);
|
||||
plugin.getServer().getPluginManager().callEvent(versionEvent);
|
||||
|
||||
final String versionInfo = versionEvent.getVersionInfo();
|
||||
|
||||
if (parsedFlags.hasFlag("--include-plugin-list")) {
|
||||
versionEvent.putDetailedVersionInfo("plugins.md", "# Plugins\n\n" + getPluginList());
|
||||
}
|
||||
|
||||
final Map<String, String> files = versionEvent.getDetailedVersionInfo();
|
||||
|
||||
|
||||
BukkitRunnable logPoster = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HashMap<String, String> pasteURLs = new HashMap<>();
|
||||
boolean hasArgs = false;
|
||||
|
||||
if (parsedFlags.hasFlag("--pastebincom")) {
|
||||
hasArgs = true;
|
||||
sendMessage(issuer, "Uploading debug info to https://pastebin.com");
|
||||
pasteURLs.put("pastebin.com", postToService(PasteServiceType.PASTEBIN, true, versionInfo, files));
|
||||
}
|
||||
|
||||
if (parsedFlags.hasFlag("--hastebin")) {
|
||||
hasArgs = true;
|
||||
sendMessage(issuer, "Uploading debug info to https://hastebin.com"); //TODO yeet it
|
||||
pasteURLs.put("hastebin.com", postToService(PasteServiceType.HASTEBIN, true, versionInfo, files));
|
||||
}
|
||||
|
||||
|
||||
if (parsedFlags.hasFlag("--logs")) {
|
||||
hasArgs = true;
|
||||
sendMessage(issuer, "Uploading logs to 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) {
|
||||
logs = "Could not read logs/latest.log";
|
||||
Logging.warning("Could not read logs/latest.log");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
pasteURLs.put("Logs", postToService(PasteServiceType.MCLOGS, false, logs, null));
|
||||
}
|
||||
|
||||
// Fallback to paste.gg if no other sites where specified
|
||||
if (parsedFlags.hasFlag("--pastegg") || !hasArgs) {
|
||||
sendMessage(issuer, "Uploading debug info to https://paste.gg");
|
||||
pasteURLs.put("paste.gg", postToService(PasteServiceType.PASTEGG, true, versionInfo, files));
|
||||
}
|
||||
|
||||
// Finally, loop through and print all URLs
|
||||
for (String service : pasteURLs.keySet()) {
|
||||
sendMessage(issuer, service + " : " + pasteURLs.get(service));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Run async as it could take some time to upload the debug info
|
||||
logPoster.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
private String getVersionString() {
|
||||
return "# Multiverse-Core Version info" + "\n\n"
|
||||
+ " - Multiverse-Core Version: " + this.plugin.getDescription().getVersion() + '\n'
|
||||
+ " - Bukkit Version: " + this.plugin.getServer().getVersion() + '\n'
|
||||
+ " - Loaded Worlds: " + worldManager.getMVWorlds() + '\n'
|
||||
+ " - Multiverse Plugins Loaded: " + this.plugin.getPluginCount() + '\n';
|
||||
}
|
||||
|
||||
private void addDebugInfoToEvent(MVVersionEvent event) {
|
||||
|
||||
// Add the legacy file, but as markdown, so it's readable
|
||||
event.putDetailedVersionInfo("version.md", this.getVersionString());
|
||||
|
||||
// add config.yml
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
event.putDetailedVersionInfo("multiverse-core/config.yml", configFile);
|
||||
|
||||
// add worlds.yml
|
||||
File worldsFile = new File(plugin.getDataFolder(), "worlds.yml");
|
||||
event.putDetailedVersionInfo("multiverse-core/worlds.yml", worldsFile);
|
||||
|
||||
// Add bukkit.yml if we found it
|
||||
if (plugin.getBukkitConfig() != null) {
|
||||
event.putDetailedVersionInfo(plugin.getBukkitConfig().getPath(), plugin.getBukkitConfig());
|
||||
} else {
|
||||
Logging.warning("/mv version could not find bukkit.yml. Not including file");
|
||||
}
|
||||
|
||||
// Add server.properties if we found it
|
||||
if (plugin.getServerProperties() != null) {
|
||||
event.putDetailedVersionInfo(plugin.getServerProperties().getPath(), plugin.getServerProperties());
|
||||
} else {
|
||||
Logging.warning("/mv version could not find server.properties. Not including file");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getPluginList() {
|
||||
return " - " + StringUtils.join(plugin.getServer().getPluginManager().getPlugins(), "\n - ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the console and player or just player if it is a console sender
|
||||
*
|
||||
* @param sender The commandSender to send the message to
|
||||
* @param message The message to be sent
|
||||
*/
|
||||
private static void sendMessage(CommandIssuer sender, String message) {
|
||||
sender.sendMessage(message);
|
||||
if (sender instanceof Player) {
|
||||
Logging.info(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current contents of this.pasteBinBuffer to a web service.
|
||||
*
|
||||
* @param type Service type to send paste data to.
|
||||
* @param isPrivate Should the paste be marked as private.
|
||||
* @param pasteData Legacy string only data to post to a service.
|
||||
* @param pasteFiles Map of filenames/contents of debug info.
|
||||
* @return URL of visible paste
|
||||
*/
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, @Nullable String pasteData, @Nullable Map<String, String> pasteFiles) {
|
||||
PasteService pasteService = PasteServiceFactory.getService(type, isPrivate);
|
||||
|
||||
try {
|
||||
String result;
|
||||
if (pasteService.supportsMultiFile()) {
|
||||
result = pasteService.postData(pasteFiles);
|
||||
} else {
|
||||
result = pasteService.postData(pasteData);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (PasteFailedException e) {
|
||||
e.printStackTrace();
|
||||
return "Error posting to service.";
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return "That service isn't supported yet.";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,11 @@
|
||||
package com.onarandombox.MultiverseCore.configuration.node;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import io.github.townyadvanced.commentedconfiguration.setting.CommentedNode;
|
||||
import io.vavr.control.Option;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A collection of {@link CommentedNode}s, with mappings to nodes by name.
|
||||
*/
|
||||
@ -49,10 +45,14 @@ public class NodeGroup implements Collection<Node> {
|
||||
return nodesMap.keySet();
|
||||
}
|
||||
|
||||
public Map<String, Node> getNodesMap() {
|
||||
return nodesMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node with the given name.
|
||||
*
|
||||
* @param name The name of the node to get.
|
||||
* @param name The name of the node to get.
|
||||
* @return The node with the given name, or {@link Option.None} if no node with the given name exists.
|
||||
*/
|
||||
public Option<Node> findNode(String name) {
|
||||
|
@ -0,0 +1,55 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import net.minidev.json.JSONObject;
|
||||
import net.minidev.json.parser.JSONParser;
|
||||
import net.minidev.json.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class McloGsPasteService extends PasteService {
|
||||
|
||||
private static final String MCLOGS_POST_REQUEST = "https://api.mclo.gs/1/log";
|
||||
|
||||
McloGsPasteService() {
|
||||
super(MCLOGS_POST_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
String encodeData(String data) {
|
||||
return "content=" + data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
String encodeData(Map<String, String> data) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String postData(String data) throws PasteFailedException {
|
||||
try {
|
||||
String stringJSON = this.exec(encodeData(data), ContentType.URLENCODED); // Execute request
|
||||
return String.valueOf(((JSONObject) new JSONParser().parse(stringJSON)).get("url")); // Interpret result
|
||||
} catch (IOException | ParseException e) {
|
||||
throw new PasteFailedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String postData(Map<String, String> data) throws PasteFailedException {
|
||||
try {
|
||||
String stringJSON = this.exec(encodeData(data), ContentType.JSON); // Execute request
|
||||
return String.valueOf(((JSONObject) new JSONParser().parse(stringJSON)).get("url")); // Interpret result
|
||||
} catch (IOException | ParseException e) {
|
||||
throw new PasteFailedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMultiFile() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -13,17 +13,12 @@ public class PasteServiceFactory {
|
||||
* @return The newly created {@link PasteService}.
|
||||
*/
|
||||
public static PasteService getService(PasteServiceType type, boolean isPrivate) {
|
||||
switch(type) {
|
||||
case PASTEGG:
|
||||
return new PasteGGPasteService(isPrivate);
|
||||
case PASTEBIN:
|
||||
return new PastebinPasteService(isPrivate);
|
||||
case HASTEBIN:
|
||||
return new HastebinPasteService();
|
||||
case GITHUB:
|
||||
return new GitHubPasteService(isPrivate);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (type) {
|
||||
case PASTEGG -> new PasteGGPasteService(isPrivate);
|
||||
case PASTEBIN -> new PastebinPasteService(isPrivate);
|
||||
case HASTEBIN -> new HastebinPasteService();
|
||||
case GITHUB -> new GitHubPasteService(isPrivate);
|
||||
case MCLOGS -> new McloGsPasteService();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,5 +22,9 @@ public enum PasteServiceType {
|
||||
/**
|
||||
* @see GitHubPasteService
|
||||
*/
|
||||
GITHUB
|
||||
GITHUB,
|
||||
/**
|
||||
* @see McloGsPasteService
|
||||
*/
|
||||
MCLOGS
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -22,16 +22,12 @@ class PastebinPasteService extends PasteService {
|
||||
*/
|
||||
@Override
|
||||
String encodeData(String data) {
|
||||
try {
|
||||
return URLEncoder.encode("api_dev_key", "UTF-8") + "=" + URLEncoder.encode("d61d68d31e8e0392b59b50b277411c71", "UTF-8") +
|
||||
"&" + URLEncoder.encode("api_option", "UTF-8") + "=" + URLEncoder.encode("paste", "UTF-8") +
|
||||
"&" + URLEncoder.encode("api_paste_code", "UTF-8") + "=" + URLEncoder.encode(data, "UTF-8") +
|
||||
"&" + URLEncoder.encode("api_paste_private", "UTF-8") + "=" + URLEncoder.encode(this.isPrivate ? "1" : "0", "UTF-8") +
|
||||
"&" + URLEncoder.encode("api_paste_format", "UTF-8") + "=" + URLEncoder.encode("yaml", "UTF-8") +
|
||||
"&" + URLEncoder.encode("api_paste_name", "UTF-8") + "=" + URLEncoder.encode("Multiverse-Core Debug Info", "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return ""; // should never hit here
|
||||
}
|
||||
return URLEncoder.encode("api_dev_key", StandardCharsets.UTF_8) + "=" + URLEncoder.encode("d61d68d31e8e0392b59b50b277411c71", StandardCharsets.UTF_8) +
|
||||
"&" + URLEncoder.encode("api_option", StandardCharsets.UTF_8) + "=" + URLEncoder.encode("paste", StandardCharsets.UTF_8) +
|
||||
"&" + URLEncoder.encode("api_paste_code", StandardCharsets.UTF_8) + "=" + URLEncoder.encode(data, StandardCharsets.UTF_8) +
|
||||
"&" + URLEncoder.encode("api_paste_private", StandardCharsets.UTF_8) + "=" + URLEncoder.encode(this.isPrivate ? "1" : "0", StandardCharsets.UTF_8) +
|
||||
"&" + URLEncoder.encode("api_paste_format", StandardCharsets.UTF_8) + "=" + URLEncoder.encode("yaml", StandardCharsets.UTF_8) +
|
||||
"&" + URLEncoder.encode("api_paste_name", StandardCharsets.UTF_8) + "=" + URLEncoder.encode("Multiverse-Core Debug Info", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,45 +7,17 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.world;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.api.LocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.api.*;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
||||
import com.onarandombox.MultiverseCore.utils.file.FileUtils;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -56,6 +28,13 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Public facing API to add/remove Multiverse worlds.
|
||||
*/
|
||||
@ -104,23 +83,27 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
this.worlds = new ConcurrentHashMap<String, MVWorld>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getDefaultWorldGenerators() {
|
||||
this.defaultGens = new HashMap<>();
|
||||
File[] files = server.getWorldContainer().listFiles((file, s) -> s.equalsIgnoreCase("bukkit.yml"));
|
||||
if (files != null && files.length == 1) {
|
||||
FileConfiguration bukkitConfig = YamlConfiguration.loadConfiguration(files[0]);
|
||||
if (bukkitConfig.isConfigurationSection("worlds")) {
|
||||
Set<String> keys = bukkitConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
for (String key : keys) {
|
||||
defaultGens.put(key, bukkitConfig.getString("worlds." + key + ".generator", ""));
|
||||
}
|
||||
|
||||
if (plugin.getBukkitConfig() == null) {
|
||||
Logging.warning("Any Default worldgenerators will not be loaded!");
|
||||
return;
|
||||
}
|
||||
|
||||
FileConfiguration bukkitConfig = YamlConfiguration.loadConfiguration(plugin.getBukkitConfig());
|
||||
|
||||
|
||||
if (bukkitConfig.isConfigurationSection("worlds")) {
|
||||
Set<String> keys = bukkitConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
for (String key : keys) {
|
||||
defaultGens.put(key, bukkitConfig.getString("worlds." + key + ".generator", ""));
|
||||
}
|
||||
} else {
|
||||
Logging.warning("Could not read 'bukkit.yml'. Any Default worldgenerators will not be loaded!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +162,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
}
|
||||
this.server.getWorld(oldName).setAutoSave(false);
|
||||
}
|
||||
|
||||
|
||||
// Grab a bit of metadata from the old world.
|
||||
MVWorld oldWorld = getMVWorld(oldName);
|
||||
|
||||
@ -207,7 +190,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
if (oldWorld != null && wasAutoSave) {
|
||||
oldWorld.getCBWorld().setAutoSave(true);
|
||||
}
|
||||
|
||||
|
||||
if (newWorldFile.exists()) {
|
||||
Logging.fine("Succeeded at copying files");
|
||||
|
||||
@ -227,8 +210,8 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
|
||||
// actually load the world
|
||||
if (doLoad(newName)) {
|
||||
Logging.fine("Succeeded at loading cloned world '" + newName + "'");
|
||||
return true;
|
||||
Logging.fine("Succeeded at loading cloned world '" + newName + "'");
|
||||
return true;
|
||||
}
|
||||
Logging.severe("Failed to load the cloned world '" + newName + "'");
|
||||
return false;
|
||||
@ -408,7 +391,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
this.worlds.remove(name);
|
||||
Logging.info("World '%s' was unloaded from Bukkit.", name);
|
||||
return true;
|
||||
} else if (!unloadBukkit){
|
||||
} else if (!unloadBukkit) {
|
||||
this.worlds.remove(name);
|
||||
Logging.info("World '%s' was unloaded from Multiverse.", name);
|
||||
return true;
|
||||
@ -992,6 +975,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
|
||||
/**
|
||||
* Gets the {@link FileConfiguration} that this {@link SimpleMVWorldManager} is using.
|
||||
*
|
||||
* @return The {@link FileConfiguration} that this {@link SimpleMVWorldManager} is using.
|
||||
*/
|
||||
public FileConfiguration getConfigWorlds() {
|
||||
@ -1001,24 +985,24 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean hasUnloadedWorld(String name, boolean includeLoaded) {
|
||||
if (getMVWorld(name) != null) {
|
||||
return includeLoaded;
|
||||
}
|
||||
for (Map.Entry<String, WorldProperties> entry : this.worldsFromTheConfig.entrySet()) {
|
||||
if (name.equals(entry.getKey()) || name.equals(entry.getValue().getAlias())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasUnloadedWorld(String name, boolean includeLoaded) {
|
||||
if (getMVWorld(name) != null) {
|
||||
return includeLoaded;
|
||||
}
|
||||
for (Map.Entry<String, WorldProperties> entry : this.worldsFromTheConfig.entrySet()) {
|
||||
if (name.equals(entry.getKey()) || name.equals(entry.getValue().getAlias())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getPotentialWorlds() {
|
||||
public Collection<String> getPotentialWorlds() {
|
||||
File worldContainer = this.server.getWorldContainer();
|
||||
if (worldContainer == null) {
|
||||
return Collections.emptyList();
|
||||
|
@ -50,6 +50,9 @@ mv-core.delete.failed=There was an issue deleting '{world}'! &fPlease check cons
|
||||
mv-core.delete.success=&aWorld {world} was deleted!
|
||||
mv-core.delete.prompt=Are you sure you want to delete world '{world}'?
|
||||
|
||||
# /mv dumps
|
||||
mv-core.dumps.description=Dumps version info to the console or paste services
|
||||
|
||||
# /mv gamerule
|
||||
mv-core.gamerule.description=Changes a gamerule in one or more worlds
|
||||
mv-core.gamerule.gamerule.description=Gamerule to set
|
||||
|
Loading…
Reference in New Issue
Block a user