Various Updates #143

Merged
SenseiKiwi merged 14 commits from master into master 2014-03-14 19:30:44 +00:00
5 changed files with 225 additions and 53 deletions
Showing only changes of commit 7e8fe10c7d - Show all commits

View File

@@ -21,7 +21,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
private CommandCreateDungeonRift()
{
super("dd-rift", "<dungeon name | 'list' | 'random'>");
super("dd-rift", "<dungeon name>");
}
public static CommandCreateDungeonRift instance()
@@ -41,7 +41,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
}
if (command.length == 0)
{
return DDCommandResult.TOO_FEW_ARGUMENTS;
@@ -50,61 +50,38 @@ public class CommandCreateDungeonRift extends DDCommandBase
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
DimLink link;
DungeonData result;
int x = MathHelper.floor_double(sender.posX);
int y = MathHelper.floor_double(sender.posY);
int z = MathHelper.floor_double (sender.posZ);
int orientation = MathHelper.floor_double((sender.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
if (command[0].equals("list"))
result = findDungeonByPartialName(command[0], dungeonHelper.getRegisteredDungeons());
if (result == null)
{
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
for (String name : dungeonNames)
{
sendChat(sender, name);
}
sendChat(sender, "");
result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
}
//Check if we found any matches
if (result != null)
{
//Create a rift to our selected dungeon and notify the player
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").");
}
else
{
DimLink link;
DungeonData result;
int x = MathHelper.floor_double(sender.posX);
int y = MathHelper.floor_double(sender.posY);
int z = MathHelper.floor_double (sender.posZ);
int orientation = MathHelper.floor_double((sender.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
if (command[0].equals("random"))
{
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to a random dungeon.");
}
else
{
result = findDungeonByPartialName(command[0], dungeonHelper.getRegisteredDungeons());
if (result == null)
{
result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
}
//Check if we found any matches
if (result != null)
{
//Create a rift to our selected dungeon and notify the player
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").");
}
else
{
//No matches!
return new DDCommandResult("Error: The specified dungeon was not found. Use 'list' to see a list of the available dungeons.");
}
}
//No matches!
return new DDCommandResult("Error: The specified dungeon was not found. Use 'dd-list' to see a list of the available dungeons.");
}
return DDCommandResult.SUCCESS;
}
private DungeonData findDungeonByPartialName(String query, Collection<DungeonData> dungeons)
private static DungeonData findDungeonByPartialName(String query, Collection<DungeonData> dungeons)
{
//Search for the shortest dungeon name that contains the lowercase query string.
String dungeonName;

View File

@@ -0,0 +1,117 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
public class CommandCreateRandomRift extends DDCommandBase
{
private static CommandCreateRandomRift instance = null;
private static Random random = new Random();
private CommandCreateRandomRift()
{
super("dd-random", "<dungeon name>");
}
public static CommandCreateRandomRift instance()
{
if (instance == null)
instance = new CommandCreateRandomRift();
return instance;
}
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
NewDimData dimension;
DungeonHelper dungeonHelper = DungeonHelper.instance();
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 1)
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
DimLink link;
DungeonData result;
int x = MathHelper.floor_double(sender.posX);
int y = MathHelper.floor_double(sender.posY);
int z = MathHelper.floor_double (sender.posZ);
int orientation = MathHelper.floor_double((sender.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
if (command.length == 0)
{
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to a random dungeon.");
}
else
{
result = getRandomDungeonByPartialName(command[0], dungeonHelper.getRegisteredDungeons());
if (result == null)
{
result = getRandomDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
}
//Check if we found any matches
if (result != null)
{
//Create a rift to our selected dungeon and notify the player
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").");
}
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 static DungeonData getRandomDungeonByPartialName(String query, Collection<DungeonData> dungeons)
{
// Search for all dungeons that contain the lowercase query string.
String dungeonName;
String normalQuery = query.toLowerCase();
ArrayList<DungeonData> matches = new ArrayList<DungeonData>();
for (DungeonData 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 = dungeon.schematicName().toLowerCase();
if (dungeonName.contains(normalQuery))
{
matches.add(dungeon);
}
}
if (matches.isEmpty())
{
return null;
}
else
{
return matches.get( random.nextInt(matches.size()) );
}
}
}

View File

@@ -0,0 +1,74 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
public class CommandListDungeons extends DDCommandBase
{
private static CommandListDungeons instance = null;
private CommandListDungeons()
{
super("dd-list", "<page>");
}
public static CommandListDungeons instance()
{
if (instance == null)
instance = new CommandListDungeons();
return instance;
}
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
int page;
int index;
int limit;
int pageCount;
ArrayList<String> dungeonNames;
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
}
if (command.length > 1)
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
if (command.length == 0)
{
page = 1;
}
else
{
try
{
page = Integer.parseInt(command[0]);
}
catch (NumberFormatException e)
{
return DDCommandResult.INVALID_ARGUMENTS;
}
}
dungeonNames = DungeonHelper.instance().getDungeonNames();
pageCount = (dungeonNames.size() - 1) / 10 + 1;
if (page < 1 || page > pageCount)
{
return DDCommandResult.INVALID_ARGUMENTS;
}
sendChat(sender, "List of dungeons (page " + page + " of " + pageCount + "):");
index = (page - 1) * 10;
limit = Math.min(index + 10, dungeonNames.size());
for (; index < limit; index++)
{
sendChat(sender, dungeonNames.get(index));
}
sendChat(sender, "");
return DDCommandResult.SUCCESS;
}
}

View File

@@ -577,11 +577,11 @@ public class DungeonHelper
return selection;
}
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.
public ArrayList<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(untaggedDungeons) );

View File

@@ -28,9 +28,11 @@ import StevenDimDoors.mod_pocketDim.blocks.UnstableDoor;
import StevenDimDoors.mod_pocketDim.blocks.WarpDoor;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift;
import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateRandomRift;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts;
import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon;
import StevenDimDoors.mod_pocketDim.commands.CommandListDungeons;
import StevenDimDoors.mod_pocketDim.commands.CommandResetDungeons;
import StevenDimDoors.mod_pocketDim.commands.CommandTeleportPlayer;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
@@ -335,6 +337,8 @@ public class mod_pocketDim
// Register commands with the server
event.registerServerCommand( CommandResetDungeons.instance() );
event.registerServerCommand( CommandCreateDungeonRift.instance() );
event.registerServerCommand( CommandListDungeons.instance() );
event.registerServerCommand( CommandCreateRandomRift.instance() );
event.registerServerCommand( CommandDeleteAllLinks.instance() );
//CommandDeleteDimensionData.instance().register(event);
event.registerServerCommand( CommandDeleteRifts.instance() );