2013-06-01 21:43:56 -04:00
|
|
|
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
|
2013-06-16 05:59:53 -04:00
|
|
|
import java.io.File;
|
2013-06-15 02:40:00 -04:00
|
|
|
|
2013-06-09 17:23:36 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-06-15 02:40:00 -04:00
|
|
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
2013-06-15 10:25:50 -04:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
2013-06-01 21:43:56 -04:00
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
public class CommandEndDungeonCreation extends DDCommandBase
|
|
|
|
{
|
|
|
|
private static CommandEndDungeonCreation instance = null;
|
2013-06-13 19:01:54 -04:00
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
private CommandEndDungeonCreation()
|
2013-06-13 19:01:54 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
super("dd-export");
|
2013-06-13 19:01:54 -04:00
|
|
|
}
|
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
public static CommandEndDungeonCreation instance()
|
2013-06-01 21:43:56 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
if (instance == null)
|
|
|
|
instance = new CommandEndDungeonCreation();
|
|
|
|
|
|
|
|
return instance;
|
2013-06-01 21:43:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-18 10:23:31 -04:00
|
|
|
protected void processCommand(EntityPlayer sender, String[] command)
|
2013-06-01 21:43:56 -04:00
|
|
|
{
|
2013-06-16 01:00:05 -04:00
|
|
|
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
2013-06-18 10:23:31 -04:00
|
|
|
DDProperties properties = DDProperties.instance();
|
2013-06-16 01:00:05 -04:00
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId))
|
2013-06-09 17:23:36 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
if (command.length < 2)
|
2013-06-09 17:23:36 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
|
2013-06-09 17:23:36 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
2013-06-09 17:44:23 -04:00
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
else if (!command[1].contains("OVERRIDE"))
|
2013-06-09 17:23:36 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
|
2013-06-09 17:23:36 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
int x = (int) sender.posX;
|
|
|
|
int y = (int) sender.posY;
|
|
|
|
int z = (int) sender.posZ;
|
2013-06-01 21:43:56 -04:00
|
|
|
|
2013-06-18 10:23:31 -04:00
|
|
|
if (command.length == 0)
|
2013-06-04 08:52:06 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
sender.sendChatToPlayer("Must name file");
|
2013-06-04 08:52:06 -04:00
|
|
|
}
|
2013-06-18 10:23:31 -04:00
|
|
|
else if(!sender.worldObj.isRemote)
|
2013-06-04 08:52:06 -04:00
|
|
|
{
|
2013-06-15 02:40:00 -04:00
|
|
|
//Check that the dungeon name is valid to prevent directory traversal and other forms of abuse
|
2013-06-18 10:23:31 -04:00
|
|
|
if (DungeonHelper.NamePattern.matcher(command[0]).matches())
|
2013-06-09 17:44:23 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
String exportPath = properties.CustomSchematicDirectory + "/" + command[0] + ".schematic";
|
|
|
|
if (dungeonHelper.exportDungeon(sender.worldObj, x, y, z, exportPath))
|
2013-06-15 02:40:00 -04:00
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
sender.sendChatToPlayer("Saved dungeon schematic in " + exportPath);
|
2013-06-16 05:59:53 -04:00
|
|
|
dungeonHelper.registerCustomDungeon(new File(exportPath));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
sender.sendChatToPlayer("Failed to save dungeon schematic!");
|
2013-06-15 02:40:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-18 10:23:31 -04:00
|
|
|
sender.sendChatToPlayer("Invalid schematic name. Please use only letters, numbers, and underscores.");
|
2013-06-09 17:44:23 -04:00
|
|
|
}
|
2013-06-04 08:52:06 -04:00
|
|
|
}
|
2013-06-01 21:43:56 -04:00
|
|
|
}
|
|
|
|
}
|