mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-09 09:47:50 +01:00
Prevent importing worlds without .dat file. Fixes #1917.
This commit is contained in:
parent
926e23bf19
commit
5e2824abeb
@ -33,9 +33,13 @@ public class DeleteCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = args.get(0);
|
||||
|
||||
Class<?>[] paramTypes = {String.class};
|
||||
List<Object> objectArgs = new ArrayList<Object>(args);
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", objectArgs,
|
||||
paramTypes, ChatColor.GREEN + "World Deleted!", ChatColor.RED + "World could NOT be deleted!");
|
||||
this.plugin.getCommandHandler()
|
||||
.queueCommand(sender, "mvdelete", "deleteWorld", objectArgs,
|
||||
paramTypes, ChatColor.GREEN + "World '" + worldName + "' Deleted!",
|
||||
ChatColor.RED + "World '" + worldName + "' could NOT be deleted!");
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class ImportCommand extends MultiverseCommand {
|
||||
File[] files = worldFolder.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return name.equalsIgnoreCase("level.dat");
|
||||
return name.toLowerCase().endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (files != null && files.length > 0) {
|
||||
@ -147,21 +147,25 @@ public class ImportCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldFile.exists() && env != null) {
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust))
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
|
||||
else
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
|
||||
if (!worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
String worldList = this.getPotentialWorlds();
|
||||
sender.sendMessage("That world folder does not exist. These look like worlds to me:");
|
||||
sender.sendMessage(worldList);
|
||||
} else if (!checkIfIsWorld(worldFile)) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage(String.format("'%s' does not appear to be a world. It is lacking a .dat file.",
|
||||
worldName));
|
||||
} else if (env == null) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage("That world environment did not exist.");
|
||||
sender.sendMessage("For a list of available world types, type: " + ChatColor.AQUA + "/mvenv");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
String worldList = this.getPotentialWorlds();
|
||||
sender.sendMessage("That world folder does not exist. These look like worlds to me:");
|
||||
sender.sendMessage(worldList);
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust))
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
|
||||
else
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.utils.MockWorldFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -90,6 +91,8 @@ public class TestWorldProperties {
|
||||
assertTrue(creator.setUp());
|
||||
core = creator.getCore();
|
||||
mockCommandSender = creator.getCommandSender();
|
||||
MockWorldFactory.createWorldDirectory("world");
|
||||
MockWorldFactory.createWorldDirectory("world_nether");
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import com.onarandombox.MultiverseCore.utils.MockWorldFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldCreatorMatcher;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
@ -99,6 +100,10 @@ public class TestWorldStuff {
|
||||
|
||||
@Test
|
||||
public void testWorldImport() {
|
||||
MockWorldFactory.createWorldDirectory("world");
|
||||
MockWorldFactory.createWorldDirectory("world_nether");
|
||||
MockWorldFactory.createWorldDirectory("world_the_end");
|
||||
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
@ -282,6 +287,9 @@ public class TestWorldStuff {
|
||||
}
|
||||
|
||||
private void createInitialWorlds(Plugin plugin, Command command) {
|
||||
MockWorldFactory.createWorldDirectory("world");
|
||||
MockWorldFactory.createWorldDirectory("world_nether");
|
||||
MockWorldFactory.createWorldDirectory("world_the_end");
|
||||
plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world", "normal" });
|
||||
plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world_nether", "nether" });
|
||||
plugin.onCommand(mockCommandSender, command, "", new String[]{ "import", "world_the_end", "end" });
|
||||
|
@ -18,6 +18,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -43,7 +44,17 @@ public class MockWorldFactory {
|
||||
private static void registerWorld(World world) {
|
||||
createdWorlds.put(world.getName(), world);
|
||||
worldUIDS.put(world.getUID(), world);
|
||||
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
|
||||
createWorldDirectory(world.getName());
|
||||
}
|
||||
|
||||
public static void createWorldDirectory(String worldName) {
|
||||
File worldFolder = new File(TestInstanceCreator.worldsDirectory, worldName);
|
||||
worldFolder.mkdir();
|
||||
try {
|
||||
new File(worldFolder, "level.dat").createNewFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static World basics(String world, World.Environment env, WorldType type) {
|
||||
|
Loading…
Reference in New Issue
Block a user