Fixed Dungeon Listing and Formatting Bugs
Added a workaround so that the dungeon list produced by CommandAddDungeonRift does not have repeated names. Also cleaned up the code a bit - it's a mess in there. Part of the rewrite eliminated the bug that caused some dungeon names to be preceded by a backslash (or slash). I've noticed a different bug now - the dungeon tutorial file is being included in the list of dungeons. I'll be fixing that in the next commit.
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.DimData;
|
||||
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
||||
import StevenDimDoors.mod_pocketDim.LinkData;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.MinecraftException;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
||||
import StevenDimDoors.mod_pocketDim.LinkData;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
|
||||
public class CommandAddDungeonRift extends CommandBase
|
||||
{
|
||||
@@ -56,37 +50,11 @@ public class CommandAddDungeonRift extends CommandBase
|
||||
}
|
||||
else if (var2.length != 0 && var2[0].equals("list"))
|
||||
{
|
||||
for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons)
|
||||
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
|
||||
for (String name : dungeonNames)
|
||||
{
|
||||
String dungeonName =dungeonGen.schematicPath;
|
||||
if(dungeonName.contains("DimDoors_Custom_schematics"))
|
||||
{
|
||||
dungeonName= dungeonName.substring(dungeonName.indexOf("DimDoors_Custom_schematics")+26);
|
||||
getCommandSenderAsPlayer(var1).sendChatToPlayer(name);
|
||||
}
|
||||
|
||||
dungeonName =dungeonName.replace("/", "").replace(".", "").replace("schematics", "").replace("schematic", "");
|
||||
|
||||
|
||||
this.getCommandSenderAsPlayer(var1).sendChatToPlayer(dungeonName);
|
||||
|
||||
}
|
||||
|
||||
for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons)
|
||||
{
|
||||
String dungeonName =dungeonGen.schematicPath;
|
||||
if(dungeonName.contains("DimDoors_Custom_schematics"))
|
||||
{
|
||||
dungeonName= dungeonName.substring(dungeonName.indexOf("DimDoors_Custom_schematics")+26);
|
||||
}
|
||||
|
||||
dungeonName =dungeonName.replace("/", "").replace(".", "").replace("schematics", "").replace("schematic", "");
|
||||
|
||||
|
||||
this.getCommandSenderAsPlayer(var1).sendChatToPlayer(dungeonName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if(var2.length!=0)
|
||||
|
||||
@@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.helpers;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
@@ -657,4 +658,30 @@ public class DungeonHelper
|
||||
}
|
||||
dimHelper.dimList.get(incoming.destDimID).dungeonGenerator = dungeon;
|
||||
}
|
||||
|
||||
public Collection<String> getDungeonNames() {
|
||||
//Use a HashSet to guarantee that all dungeon names will be distinct.
|
||||
//This shouldn't be necessary if we keep proper lists without repetitions,
|
||||
//but it's a fool-proof workaround.
|
||||
HashSet<String> dungeonNames = new HashSet<String>();
|
||||
dungeonNames.addAll( parseDungeonNames(registeredDungeons) );
|
||||
dungeonNames.addAll( parseDungeonNames(customDungeons) );
|
||||
return dungeonNames;
|
||||
}
|
||||
|
||||
private static ArrayList<String> parseDungeonNames(ArrayList<DungeonGenerator> dungeons)
|
||||
{
|
||||
String name;
|
||||
File schematic;
|
||||
ArrayList<String> names = new ArrayList<String>(dungeons.size());
|
||||
|
||||
for (DungeonGenerator dungeon : dungeons)
|
||||
{
|
||||
schematic = new File(dungeon.schematicPath);
|
||||
name = schematic.getName();
|
||||
name = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length());
|
||||
names.add(name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user