Reviewed and Rewrote Commands #169

Merged
SenseiKiwi merged 17 commits from master into master 2014-07-06 01:59:42 +00:00
Showing only changes of commit 80bb87dac6 - Show all commits

View File

@@ -8,6 +8,7 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
public class CommandDeleteRifts extends DDCommandBase public class CommandDeleteRifts extends DDCommandBase
{ {
@@ -15,7 +16,7 @@ public class CommandDeleteRifts extends DDCommandBase
private CommandDeleteRifts() private CommandDeleteRifts()
{ {
super("dd-???", "???"); super("dd-deleterifts", "[dimension number]");
} }
public static CommandDeleteRifts instance() public static CommandDeleteRifts instance()
@@ -30,46 +31,63 @@ public class CommandDeleteRifts extends DDCommandBase
protected DDCommandResult processCommand(EntityPlayer sender, String[] command) protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{ {
int linksRemoved = 0; int linksRemoved = 0;
int targetDim; int targetDimension;
boolean shouldGo= true;
if(command.length==1) if (command.length > 1)
{ {
targetDim = parseInt(sender, command[0]); return DDCommandResult.TOO_MANY_ARGUMENTS;
}
if (command.length == 0)
{
targetDimension = sender.worldObj.provider.dimensionId;
} }
else else
{ {
targetDim=0; try
shouldGo=false; {
sendChat(sender,("Error-Invalid argument, delete_all_links <targetDimID>")); targetDimension = Integer.parseInt(command[0]);
}
catch (NumberFormatException e)
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
} }
if(shouldGo) World world = PocketManager.loadDimension(targetDimension);
if (world == null)
{ {
return DDCommandResult.UNREGISTERED_DIMENSION;
}
NewDimData dim = PocketManager.getDimensionData(targetDim); int x;
ArrayList<DimLink> linksInDim = dim.getAllLinks(); int y;
int z;
for (DimLink link : linksInDim) Point4D location;
NewDimData dimension = PocketManager.getDimensionData(targetDimension);
ArrayList<DimLink> links = dimension.getAllLinks();
for (DimLink link : links)
{ {
World targetWorld = PocketManager.loadDimension(targetDim); location = link.source();
x = location.getX();
if(!mod_pocketDim.blockRift.isBlockImmune(sender.worldObj,link.source().getX(), link.source().getY(), link.source().getZ())|| y = location.getY();
(targetWorld.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID)) z = location.getZ();
if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID)
{ {
// Remove the rift and its link
world.setBlockToAir(x, y, z);
dimension.deleteLink(link);
linksRemoved++; linksRemoved++;
targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0);
dim.deleteLink(link);
} }
//TODO Probably should check what the block is, but thats annoying so Ill do it later. else if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z))
{
// If a block is not immune, then it must not be a DD block.
} // The link would regenerate into a rift eventually.
sendChat(sender,("Removed " + linksRemoved + " links.")); // We only need to remove the link.
dimension.deleteLink(link);
} linksRemoved++;
return DDCommandResult.SUCCESS; //TEMPORARY HACK }
}
sendChat(sender, "Removed " + linksRemoved + " links.");
return DDCommandResult.SUCCESS;
} }
} }