2013-03-23 07:29:20 +01:00
|
|
|
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.world.World;
|
2013-03-23 07:29:20 +01:00
|
|
|
import StevenDimDoors.mod_pocketDim.DimData;
|
|
|
|
import StevenDimDoors.mod_pocketDim.LinkData;
|
2013-06-10 23:03:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
2013-03-23 07:29:20 +01:00
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
public class CommandDeleteAllLinks extends DDCommandBase
|
2013-03-23 07:29:20 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
private static CommandDeleteAllLinks instance = null;
|
|
|
|
|
|
|
|
private CommandDeleteAllLinks()
|
2013-03-23 07:29:20 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
super("dd-deletelinks");
|
2013-03-23 07:29:20 +01:00
|
|
|
}
|
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
public static CommandDeleteAllLinks instance()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
instance = new CommandDeleteAllLinks();
|
2013-03-23 07:29:20 +01:00
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
return instance;
|
|
|
|
}
|
2013-03-23 07:29:20 +01:00
|
|
|
|
|
|
|
@Override
|
2013-06-18 16:23:31 +02:00
|
|
|
protected void processCommand(EntityPlayer sender, String[] command)
|
2013-03-23 07:29:20 +01:00
|
|
|
{
|
|
|
|
int linksRemoved=0;
|
|
|
|
int targetDim;
|
|
|
|
boolean shouldGo= true;
|
2013-06-18 16:23:31 +02:00
|
|
|
|
|
|
|
if(command.length==0)
|
2013-03-23 07:29:20 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
targetDim= sender.worldObj.provider.dimensionId;
|
2013-03-23 07:29:20 +01:00
|
|
|
}
|
2013-06-18 16:23:31 +02:00
|
|
|
else if(command.length==1)
|
2013-03-23 07:29:20 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
targetDim = parseInt(sender, command[0]);
|
2013-03-23 07:29:20 +01:00
|
|
|
if(!dimHelper.dimList.containsKey(targetDim))
|
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered");
|
2013-03-23 07:29:20 +01:00
|
|
|
shouldGo=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
targetDim=0;
|
|
|
|
shouldGo=false;
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Error-Invalid argument, delete_all_links <targetDimID> or blank for current dim");
|
2013-03-23 07:29:20 +01:00
|
|
|
}
|
2013-06-18 16:23:31 +02:00
|
|
|
|
2013-03-23 07:29:20 +01:00
|
|
|
if(shouldGo)
|
|
|
|
{
|
|
|
|
if(dimHelper.dimList.containsKey(targetDim))
|
|
|
|
{
|
|
|
|
DimData dim = dimHelper.dimList.get(targetDim);
|
|
|
|
ArrayList<LinkData> linksInDim = dim.printAllLinkData();
|
2013-06-18 16:23:31 +02:00
|
|
|
|
|
|
|
for (LinkData link : linksInDim)
|
2013-03-23 07:29:20 +01:00
|
|
|
{
|
|
|
|
World targetWorld = dimHelper.getWorld(targetDim);
|
2013-06-18 16:23:31 +02:00
|
|
|
|
2013-03-23 07:29:20 +01:00
|
|
|
if(targetWorld==null)
|
|
|
|
{
|
|
|
|
dimHelper.initDimension(targetDim);
|
|
|
|
}
|
|
|
|
else if(targetWorld.provider==null)
|
|
|
|
{
|
|
|
|
dimHelper.initDimension(targetDim);
|
|
|
|
}
|
|
|
|
targetWorld = dimHelper.getWorld(targetDim);
|
2013-06-18 16:23:31 +02:00
|
|
|
dim.removeLinkAtCoords(link);
|
|
|
|
targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0);
|
|
|
|
linksRemoved++;
|
2013-03-23 07:29:20 +01:00
|
|
|
}
|
|
|
|
//dim.linksInThisDim.clear();
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Removed " + linksRemoved + " links.");
|
2013-03-23 07:29:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|