Major Improvements to DungeonHelper, Minor Bug Fixes and Tweaks #25
@@ -8,11 +8,11 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||||
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
||||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||||
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||||
|
|
||||||
public class CommandEndDungeonCreation extends CommandBase
|
public class CommandEndDungeonCreation extends CommandBase
|
||||||
{
|
{
|
||||||
private static DDProperties properties = null;
|
private static DDProperties properties = null;
|
||||||
private static Pattern nameFilter = Pattern.compile("[A-Za-z0-9_]+");
|
|
||||||
|
|
||||||
public CommandEndDungeonCreation()
|
public CommandEndDungeonCreation()
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@ public class CommandEndDungeonCreation extends CommandBase
|
|||||||
else if(!player.worldObj.isRemote)
|
else if(!player.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
//Check that the dungeon name is valid to prevent directory traversal and other forms of abuse
|
//Check that the dungeon name is valid to prevent directory traversal and other forms of abuse
|
||||||
if (nameFilter.matcher(var2[0]).matches())
|
if (DungeonHelper.NamePattern.matcher(var2[0]).matches())
|
||||||
{
|
{
|
||||||
DungeonGenerator newDungeon = mod_pocketDim.dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic");
|
DungeonGenerator newDungeon = mod_pocketDim.dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic");
|
||||||
player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic");
|
player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
@@ -25,6 +26,10 @@ public class DungeonHelper
|
|||||||
private static DDProperties properties = null;
|
private static DDProperties properties = null;
|
||||||
|
|
||||||
private Random rand = new Random();
|
private Random rand = new Random();
|
||||||
|
private static final String SCHEMATIC_FILE_EXTENSION = ".schematic";
|
||||||
|
private static final int DEFAULT_DUNGEON_WEIGHT = 100;
|
||||||
|
|
||||||
|
public static Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+");
|
||||||
|
|
||||||
public HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>();
|
public HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>();
|
||||||
|
|
||||||
@@ -53,40 +58,60 @@ public class DungeonHelper
|
|||||||
properties = DDProperties.instance();
|
properties = DDProperties.instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCustomDungeon(File schematicFile)
|
public boolean validateSchematicName(String name)
|
||||||
|
{
|
||||||
|
String[] dungeonData = name.split("_");
|
||||||
|
|
||||||
|
//Check for a valid number of parts
|
||||||
|
if (dungeonData.length < 3 || dungeonData.length > 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//Check if the category is valid
|
||||||
|
if (!tagList.contains(dungeonData[0]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//Check if the name is valid
|
||||||
|
if (!NamePattern.matcher(dungeonData[1]).matches())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//Check if the open/closed flag is present
|
||||||
|
if (!dungeonData[2].equalsIgnoreCase("open") && !dungeonData[2].equalsIgnoreCase("closed"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//If the weight is present, check that it is valid
|
||||||
|
if (dungeonData.length == 4)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(schematicFile.getName().contains(".schematic"))
|
int weight = Integer.parseInt(dungeonData[3]);
|
||||||
{
|
if (weight < 0)
|
||||||
String[] name = schematicFile.getName().split("_");
|
return false;
|
||||||
|
|
||||||
if(name.length<4)
|
|
||||||
{
|
|
||||||
System.out.println("Could not parse filename tags, not adding dungeon to generation lists");
|
|
||||||
this.customDungeons.add(new DungeonGenerator(0,schematicFile.getAbsolutePath(),true));
|
|
||||||
System.out.println("Imported "+schematicFile.getName());
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(!(name[2].equals("open")||name[2].equals("closed"))||!this.tagList.contains(name[0]))
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
System.out.println("Could not parse filename tags, not adding dungeon to generation lists");
|
//Not a number
|
||||||
this.customDungeons.add(new DungeonGenerator(0,schematicFile.getAbsolutePath(),true));
|
return false;
|
||||||
System.out.println("Imported "+schematicFile.getName());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCustomDungeon(File schematicFile)
|
||||||
{
|
{
|
||||||
int count=0;
|
String name = schematicFile.getName();
|
||||||
|
try
|
||||||
boolean open= name[2].equals("open");
|
{
|
||||||
|
if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name))
|
||||||
int weight = Integer.parseInt(name[3].replace(".schematic", ""));
|
{
|
||||||
|
//Strip off the file extension while splitting the file name
|
||||||
|
String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
||||||
|
|
||||||
String path = schematicFile.getAbsolutePath();
|
String path = schematicFile.getAbsolutePath();
|
||||||
|
boolean open = dungeonData[2].equals("open");
|
||||||
|
int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT;
|
||||||
|
|
||||||
while(count<weight)
|
//Change this code so that instead of using IFs, we use a hash table mapping (category) -> (list)
|
||||||
|
/*while(count<weight)
|
||||||
{
|
{
|
||||||
if(name[0].equals("hub"))
|
if(name[0].equals("hub"))
|
||||||
{
|
{
|
||||||
@@ -124,16 +149,22 @@ public class DungeonHelper
|
|||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
this.weightedDungeonGenList.add(new DungeonGenerator(weight,path,open));
|
this.weightedDungeonGenList.add(new DungeonGenerator(weight,path,open));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
registeredDungeons.add(new DungeonGenerator(weight, path, open));
|
||||||
|
System.out.println("Imported " + name);
|
||||||
}
|
}
|
||||||
this.registeredDungeons.add(new DungeonGenerator(weight,path,open));
|
else
|
||||||
System.out.println("Imported "+schematicFile.getName());
|
{
|
||||||
}
|
System.out.println("Could not parse dungeon filename, not adding dungeon to generation lists");
|
||||||
|
customDungeons.add(new DungeonGenerator(0, schematicFile.getAbsolutePath(), true));
|
||||||
|
System.out.println("Imported " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("Importing custom dungeon failed");
|
System.out.println("Failed to import " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user