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