DimDoors/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java

80 lines
2.1 KiB
Java
Raw Normal View History

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