Copy Command

Small Fixes
Single Imports IntellIJ config
This commit is contained in:
Shaun Bennett 2014-08-16 20:17:21 -05:00
parent b6c31294c7
commit 6793deffd0
9 changed files with 132 additions and 30 deletions

View File

@ -5,7 +5,6 @@
<value>
<option name="FIELD_NAME_PREFIX" value="_" />
<option name="STATIC_FIELD_NAME_PREFIX" value="_" />
<option name="USE_SINGLE_CLASS_IMPORTS" value="false" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10" />
<option name="IMPORT_LAYOUT_TABLE">

View File

@ -9,7 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Mineplex.Core.Common" />
<orderEntry type="library" name="craftbukkit" level="project" />
<orderEntry type="library" name="commons-io" level="project" />
</component>
</module>

View File

@ -1,21 +1,12 @@
package mineplex.mapparser;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.mapparser.command.*;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -40,6 +31,29 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.mapparser.command.AuthorCommand;
import mineplex.mapparser.command.BaseCommand;
import mineplex.mapparser.command.BuildCommand;
import mineplex.mapparser.command.CopyCommand;
import mineplex.mapparser.command.CopySchematicsCommand;
import mineplex.mapparser.command.CreateCommand;
import mineplex.mapparser.command.DeleteCommand;
import mineplex.mapparser.command.GameTypeCommand;
import mineplex.mapparser.command.HubCommand;
import mineplex.mapparser.command.ListCommand;
import mineplex.mapparser.command.MapCommand;
import mineplex.mapparser.command.NameCommand;
import mineplex.mapparser.command.ParseCommand;
import mineplex.mapparser.command.RenameCommand;
import mineplex.mapparser.command.SaveCommand;
import mineplex.mapparser.command.WorldsCommand;
public class MapParser extends JavaPlugin implements Listener
{
private WorldManager _worldManager;
@ -76,6 +90,7 @@ public class MapParser extends JavaPlugin implements Listener
_commands.add(new RenameCommand(this));
_commands.add(new SaveCommand(this));
_commands.add(new WorldsCommand(this));
_commands.add(new CopyCommand(this));
}
@Override
@ -149,7 +164,8 @@ public class MapParser extends JavaPlugin implements Listener
{
if (!command.execute(player, commandLabel, args))
{
UtilPlayer.message(player, F.main("Parser", "Invalid Input. " + command.getUsage()));
UtilPlayer.message(player, F.main("Parser", "Invalid Input."));
UtilPlayer.message(player, F.elem(command.getUsage()));
}
event.setCancelled(true);
@ -260,7 +276,7 @@ public class MapParser extends JavaPlugin implements Listener
if (world.getPlayers().isEmpty())
{
Announce("Saving & Closing World: " + F.elem(world.getName()));
Announce("Saving & Closing World: " + F.elem(world.getName()));
MapUtil.UnloadWorld(this, world, true);
}
}
@ -317,9 +333,9 @@ public class MapParser extends JavaPlugin implements Listener
return null;
}
public String getWorldString(String worldName, GameType type)
public String getWorldString(String mapName, GameType type)
{
return "map" + "/" + type.GetName() + "/" + worldName;
return "map" + "/" + type.GetName() + "/" + mapName;
}
public List<String> getMapsByName(String name)

View File

@ -4,17 +4,14 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.WorldUtil;
import mineplex.core.common.util.ZipUtil;
import net.minecraft.util.org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.util.org.apache.commons.io.FileUtils;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.ZipUtil;
public class WorldManager
{

View File

@ -0,0 +1,94 @@
package mineplex.mapparser.command;
import java.io.File;
import java.io.IOException;
import org.bukkit.World;
import org.bukkit.entity.Player;
import net.minecraft.util.org.apache.commons.io.FileUtils;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.mapparser.GameType;
import mineplex.mapparser.MapParser;
/**
* Created by Shaun on 8/16/2014.
*/
public class CopyCommand extends BaseCommand
{
public CopyCommand(MapParser plugin)
{
super(plugin, "copy");
setUsage("/copy <map name> <game type> <copy map name> <copy game time>");
setDescription("Copy the data of a map into a new map. This preserves Build List.");
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
if (args.length != 4)
return false;
String originalMapName = args[0];
String newMapName = args[2];
GameType originalGametype = null;
GameType newGameType = null;
try
{
originalGametype = GameType.valueOf(args[1]);
newGameType = GameType.valueOf(args[3]);
}
catch (Exception e)
{
getPlugin().sendValidGameTypes(player);
return true;
}
String worldName = getPlugin().getWorldString(originalMapName, originalGametype);
String newWorldName = getPlugin().getWorldString(newMapName, newGameType);
if (!getPlugin().DoesMapExist(worldName))
{
message(player, "Could not find a map with the name " + F.elem(originalMapName) + " of type " + F.elem(originalGametype.toString()));
return true;
}
if (getPlugin().DoesMapExist(newWorldName))
{
message(player, "Destination map already exists " + F.elem(newMapName) + " of type " + F.elem(newGameType.toString()));
return true;
}
World world = getPlugin().GetMapWorld(worldName);
if (world != null)
{
// World is loaded, save and unload it.
for (Player other : world.getPlayers())
{
other.teleport(getPlugin().getSpawnLocation());
message(other, "Unloading world for copy...");
}
MapUtil.UnloadWorld(getPlugin(), world, true);
}
File source = new File(worldName);
File destination = new File(newWorldName);
try
{
FileUtils.copyDirectory(source, destination);
message(player, "Copy completed successfully!");
}
catch (IOException e)
{
e.printStackTrace();
message(player, "An error occurred during map copy!");
}
return true;
}
}

View File

@ -4,9 +4,9 @@ import java.io.File;
import java.io.IOException;
import org.bukkit.entity.Player;
import net.minecraft.util.org.apache.commons.io.FileUtils;
import mineplex.mapparser.MapParser;
import org.apache.commons.io.FileUtils;
/**
* Created by Shaun on 8/16/2014.

View File

@ -2,16 +2,14 @@ package mineplex.mapparser.command;
import java.io.File;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import net.minecraft.util.org.apache.commons.io.FileUtils;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilPlayer;
import mineplex.mapparser.GameType;
import mineplex.mapparser.MapParser;
import org.apache.commons.io.FileUtils;
/**
* Created by Shaun on 8/16/2014.
@ -79,6 +77,6 @@ public class DeleteCommand extends BaseCommand
else
getPlugin().Announce("Failed to delete World: " + F.elem(worldName));
return false;
return true;
}
}

View File

@ -110,6 +110,6 @@ public class MapCommand extends BaseCommand
UtilPlayer.message(player, F.value("Map Name", data.MapName));
UtilPlayer.message(player, F.value("Author", data.MapCreator));
UtilPlayer.message(player, F.value("Game Type", data.GameType.GetName()));
return false;
return true;
}
}

View File

@ -2,7 +2,6 @@ package mineplex.mapparser.command;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -74,6 +73,6 @@ public class SaveCommand extends BaseCommand
getPlugin().Announce("Saved World: " + F.elem(args[0]));
return false;
return true;
}
}