Partial Overhaul of Commands
Made progress on overhauling and prettifying our commands. There are still more changes to be done for this to be functional. I need to do an intermediate commit because I want to merge in recent changes by Steven.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
||||
import StevenDimDoors.mod_pocketDim.LinkData;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||
@@ -15,7 +15,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
|
||||
|
||||
private CommandCreateDungeonRift()
|
||||
{
|
||||
super("dd-rift");
|
||||
super("dd-rift", "<dungeon name | 'list' | 'random'>");
|
||||
}
|
||||
|
||||
public static CommandCreateDungeonRift instance()
|
||||
@@ -27,71 +27,101 @@ public class CommandCreateDungeonRift extends DDCommandBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(EntityPlayer sender, String[] command)
|
||||
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
||||
{
|
||||
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
||||
|
||||
if(command==null||sender.worldObj.isRemote)
|
||||
if (sender.worldObj.isRemote)
|
||||
{
|
||||
return;
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
if (command.length == 0)
|
||||
{
|
||||
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
||||
}
|
||||
if (command.length > 1)
|
||||
{
|
||||
return DDCommandResult.TOO_MANY_ARGUMENTS;
|
||||
}
|
||||
|
||||
LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0,
|
||||
(int) sender.posX,
|
||||
(int) sender.posY + 1,
|
||||
(int) sender.posZ,
|
||||
(int) sender.posX,
|
||||
(int) sender.posY + 1,
|
||||
(int) sender.posZ,true,3);
|
||||
|
||||
if(command.length!=0&&command[0].equals("random"))
|
||||
{
|
||||
sender.sendChatToPlayer("Created dungeon rift");
|
||||
dimHelper.instance.createLink(link);
|
||||
link = dimHelper.instance.createPocket(link,true, true);
|
||||
}
|
||||
else if (command.length != 0 && command[0].equals("list"))
|
||||
if (command[0].equals("list"))
|
||||
{
|
||||
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
|
||||
for (String name : dungeonNames)
|
||||
{
|
||||
getCommandSenderAsPlayer(sender).sendChatToPlayer(name);
|
||||
}
|
||||
}
|
||||
else if(command.length!=0)
|
||||
{
|
||||
for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons)
|
||||
{
|
||||
String dungeonName =dungeonGen.schematicPath.toLowerCase();
|
||||
|
||||
if(dungeonName.contains(command[0].toLowerCase()))
|
||||
{
|
||||
link = dimHelper.instance.createPocket(link,true, true);
|
||||
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
|
||||
sender.sendChatToPlayer("Genned dungeon " +dungeonName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons)
|
||||
{
|
||||
String dungeonName =dungeonGen.schematicPath.toLowerCase();
|
||||
|
||||
if(dungeonName.contains(command[0].toLowerCase()))
|
||||
{
|
||||
link = dimHelper.instance.createPocket(link,true, true);
|
||||
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
|
||||
sender.sendChatToPlayer("Genned dungeon " +dungeonName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(command!=null&&!command[0].equals("random"))
|
||||
{
|
||||
sender.sendChatToPlayer("could not find dungeon, 'list' for list of dungeons");
|
||||
sender.sendChatToPlayer(name);
|
||||
}
|
||||
sender.sendChatToPlayer("");
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendChatToPlayer("invalid arguments- 'random' for random dungeon, or 'list' for dungeon names");
|
||||
DungeonGenerator result;
|
||||
int x = (int) sender.posX;
|
||||
int y = (int) sender.posY;
|
||||
int z = (int) sender.posZ;
|
||||
LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3);
|
||||
|
||||
if (command[0].equals("random"))
|
||||
{
|
||||
dimHelper.instance.createLink(link);
|
||||
link = dimHelper.instance.createPocket(link, true, true);
|
||||
sender.sendChatToPlayer("Created a rift to a random dungeon (Dimension ID = " + link.destDimID + ").");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = findDungeonByPartialName(command[0], dungeonHelper.registeredDungeons);
|
||||
if (result == null)
|
||||
{
|
||||
result = findDungeonByPartialName(command[0], dungeonHelper.customDungeons);
|
||||
}
|
||||
//Check if we found any matches
|
||||
if (result != null)
|
||||
{
|
||||
//Create a rift to our selected dungeon and notify the player
|
||||
link = dimHelper.instance.createPocket(link, true, true);
|
||||
dimHelper.dimList.get(link.destDimID).dungeonGenerator = result;
|
||||
sender.sendChatToPlayer("Created a rift to \"" + getSchematicName(result) + "\" dungeon (Dimension ID = " + link.destDimID + ").");
|
||||
}
|
||||
else
|
||||
{
|
||||
//No matches!
|
||||
return new DDCommandResult("Error: The specified dungeon was not found. Use 'list' to see a list of the available dungeons.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
private DungeonGenerator findDungeonByPartialName(String query, Collection<DungeonGenerator> dungeons)
|
||||
{
|
||||
//Search for the shortest dungeon name that contains the lowercase query string.
|
||||
String dungeonName;
|
||||
String normalQuery = query.toLowerCase();
|
||||
DungeonGenerator bestMatch = null;
|
||||
int matchLength = Integer.MAX_VALUE;
|
||||
|
||||
for (DungeonGenerator dungeon : dungeons)
|
||||
{
|
||||
//We need to extract the file's name. Comparing against schematicPath could
|
||||
//yield false matches if the query string is contained within the path.
|
||||
|
||||
dungeonName = getSchematicName(dungeon).toLowerCase();
|
||||
if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery))
|
||||
{
|
||||
matchLength = dungeonName.length();
|
||||
bestMatch = dungeon;
|
||||
}
|
||||
}
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
private static String getSchematicName(DungeonGenerator dungeon)
|
||||
{
|
||||
//TODO: Move this to DungeonHelper and use it for all schematic name parsing.
|
||||
//In the future, we really should include the schematic's name as part of DungeonGenerator
|
||||
//to avoid redoing this work constantly.
|
||||
File schematic = new File(dungeon.schematicPath);
|
||||
String fileName = schematic.getName();
|
||||
return fileName.substring(0, fileName.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user