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-08-29 08:14:24 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.ILinkData;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
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-08-29 08:14:24 +02:00
|
|
|
if(!PocketManager.dimList.containsKey(targetDim))
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
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)
|
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
if(PocketManager.dimList.containsKey(targetDim))
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-03-24 06:12:48 +01:00
|
|
|
try
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
for(NewDimData newDimData :PocketManager.dimList.values())
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
Collection<ILinkData> links= new ArrayList<ILinkData>();
|
|
|
|
links.addAll( newDimData.getLinksInDim());
|
2013-03-24 06:12:48 +01:00
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
for(ILinkData link : links)
|
2013-03-24 05:52:50 +01:00
|
|
|
{
|
2013-03-24 06:12:48 +01:00
|
|
|
if(link.destDimID==targetDim)
|
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
PocketManager.instance.getDimData(link.locDimID).removeLinkAtCoords(link);
|
2013-03-24 06:12:48 +01:00
|
|
|
linksRemoved++;
|
|
|
|
}
|
2013-08-29 08:14:24 +02:00
|
|
|
if(newDimData.dimID==targetDim)
|
2013-03-24 06:12:48 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
PocketManager.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
|
|
|
}
|
|
|
|
}
|