2013-03-24 05:52:50 +01:00
|
|
|
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-03-24 05:52:50 +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-24 05:52:50 +01:00
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
public class CommandDeleteDimensionData extends DDCommandBase
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
private static CommandDeleteDimensionData instance = null;
|
|
|
|
|
|
|
|
private CommandDeleteDimensionData()
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-07-16 23:00:25 +02:00
|
|
|
super("dd-deletedimension", "???");
|
2013-06-18 16:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CommandDeleteDimensionData instance()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
instance = new CommandDeleteDimensionData();
|
|
|
|
|
|
|
|
return instance;
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-25 19:55:13 +02:00
|
|
|
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
|
|
|
int linksRemoved=0;
|
|
|
|
int targetDim;
|
|
|
|
boolean shouldGo= true;
|
|
|
|
|
2013-06-18 16:23:31 +02:00
|
|
|
if (command.length==0)
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
targetDim= sender.worldObj.provider.dimensionId;
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
2013-06-18 16:23:31 +02:00
|
|
|
else if (command.length==1)
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
targetDim = parseInt(sender, command[0]);
|
2013-03-24 05:52:50 +01:00
|
|
|
if(!dimHelper.dimList.containsKey(targetDim))
|
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered");
|
2013-03-24 05:52:50 +01:00
|
|
|
shouldGo=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
targetDim=0;
|
|
|
|
shouldGo=false;
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Error-Invalid argument, delete_dim_data <targetDimID> or blank for current dim");
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(shouldGo)
|
|
|
|
{
|
|
|
|
if(dimHelper.dimList.containsKey(targetDim))
|
|
|
|
{
|
2013-03-24 06:12:48 +01:00
|
|
|
try
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-03-24 06:12:48 +01:00
|
|
|
for(DimData dimData :dimHelper.dimList.values())
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
Collection<LinkData> links= new ArrayList<LinkData>();
|
2013-07-12 02:42:57 +02:00
|
|
|
links.addAll( dimData.getLinksInDim());
|
2013-03-24 06:12:48 +01:00
|
|
|
|
|
|
|
for(LinkData link : links)
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-03-24 06:12:48 +01:00
|
|
|
if(link.destDimID==targetDim)
|
|
|
|
{
|
|
|
|
dimHelper.dimList.get(link.locDimID).removeLinkAtCoords(link);
|
|
|
|
linksRemoved++;
|
|
|
|
}
|
|
|
|
if(dimData.dimID==targetDim)
|
|
|
|
{
|
|
|
|
linksRemoved++;
|
|
|
|
}
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
2013-03-24 06:12:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dimHelper.dimList.remove(targetDim);
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Removed dimension " + targetDim + " from DimDoors and deleted " + linksRemoved + " links");
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-18 16:23:31 +02:00
|
|
|
sender.sendChatToPlayer("Error- dimension "+targetDim+" not registered with dimDoors");
|
|
|
|
}
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
2013-06-26 05:24:21 +02:00
|
|
|
return DDCommandResult.SUCCESS; //TEMPORARY HACK
|
2013-03-24 05:52:50 +01:00
|
|
|
}
|
|
|
|
}
|