2013-06-18 16:23:31 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-08-23 07:30:24 +02:00
|
|
|
import net.minecraft.util.MathHelper;
|
2013-08-29 08:14:24 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.core.IDimLink;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
|
|
|
import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
|
2013-06-18 16:23:31 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
|
|
|
|
|
|
|
public class CommandCreateDungeonRift extends DDCommandBase
|
|
|
|
{
|
|
|
|
private static CommandCreateDungeonRift instance = null;
|
|
|
|
|
|
|
|
private CommandCreateDungeonRift()
|
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
super("dd-rift", "<dungeon name | 'list' | 'random'>");
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CommandCreateDungeonRift instance()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
instance = new CommandCreateDungeonRift();
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-25 19:55:13 +02:00
|
|
|
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
|
|
|
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
|
|
|
|
2013-06-25 19:55:13 +02:00
|
|
|
if (sender.worldObj.isRemote)
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
return DDCommandResult.SUCCESS;
|
|
|
|
}
|
|
|
|
if (command.length == 0)
|
|
|
|
{
|
|
|
|
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
if (command.length > 1)
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
return DDCommandResult.TOO_MANY_ARGUMENTS;
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
|
|
|
|
if (command[0].equals("list"))
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
|
|
|
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
|
|
|
|
for (String name : dungeonNames)
|
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
sender.sendChatToPlayer(name);
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
sender.sendChatToPlayer("");
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
else
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
IDimLink link;
|
|
|
|
DungeonData result;
|
2013-08-23 07:30:24 +02:00
|
|
|
int x = MathHelper.floor_double(sender.posX);
|
|
|
|
int y = MathHelper.floor_double(sender.posY);
|
|
|
|
int z = MathHelper.floor_double (sender.posZ);
|
2013-06-25 19:55:13 +02:00
|
|
|
|
|
|
|
if (command[0].equals("random"))
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3);
|
|
|
|
PocketManager.createLink(link);
|
|
|
|
link = PocketManager.createPocket(link, true, true);
|
2013-06-25 19:55:13 +02:00
|
|
|
sender.sendChatToPlayer("Created a rift to a random dungeon (Dimension ID = " + link.destDimID + ").");
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
else
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-08-01 06:05:08 +02:00
|
|
|
result = findDungeonByPartialName(command[0], dungeonHelper.getRegisteredDungeons());
|
2013-06-25 19:55:13 +02:00
|
|
|
if (result == null)
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-08-01 06:05:08 +02:00
|
|
|
result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
|
2013-06-25 19:55:13 +02:00
|
|
|
}
|
|
|
|
//Check if we found any matches
|
|
|
|
if (result != null)
|
|
|
|
{
|
|
|
|
//Create a rift to our selected dungeon and notify the player
|
2013-08-29 08:14:24 +02:00
|
|
|
link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3);
|
|
|
|
link = PocketManager.instance.createPocket(link, true, true);
|
|
|
|
PocketManager.instance.getDimData(link.destDimID).dungeonGenerator = result;
|
|
|
|
sender.sendChatToPlayer("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination.getDimensionID() + ").");
|
2013-06-25 19:55:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//No matches!
|
|
|
|
return new DDCommandResult("Error: The specified dungeon was not found. Use 'list' to see a list of the available dungeons.");
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
return DDCommandResult.SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
private DungeonData findDungeonByPartialName(String query, Collection<DungeonData> dungeons)
|
2013-06-25 19:55:13 +02:00
|
|
|
{
|
|
|
|
//Search for the shortest dungeon name that contains the lowercase query string.
|
|
|
|
String dungeonName;
|
|
|
|
String normalQuery = query.toLowerCase();
|
2013-08-29 08:14:24 +02:00
|
|
|
DungeonData bestMatch = null;
|
2013-06-25 19:55:13 +02:00
|
|
|
int matchLength = Integer.MAX_VALUE;
|
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
for (DungeonData dungeon : dungeons)
|
2013-06-18 16:23:31 +02:00
|
|
|
{
|
2013-06-25 19:55:13 +02:00
|
|
|
//We need to extract the file's name. Comparing against schematicPath could
|
|
|
|
//yield false matches if the query string is contained within the path.
|
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
dungeonName = dungeon.schematicName().toLowerCase();
|
2013-06-25 19:55:13 +02:00
|
|
|
if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery))
|
|
|
|
{
|
|
|
|
matchLength = dungeonName.length();
|
|
|
|
bestMatch = dungeon;
|
|
|
|
}
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
2013-06-25 19:55:13 +02:00
|
|
|
return bestMatch;
|
|
|
|
}
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|