2013-06-25 20:28:11 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
|
2013-11-06 00:15:23 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-11-06 22:40:49 +01:00
|
|
|
import net.minecraft.command.ICommandSender;
|
2013-06-25 20:28:11 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-11-06 00:15:23 +01:00
|
|
|
import net.minecraftforge.common.DimensionManager;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
2013-06-25 20:28:11 +02:00
|
|
|
|
2013-11-07 00:15:30 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2013-06-25 20:28:11 +02:00
|
|
|
public class CommandResetDungeons extends DDCommandBase
|
|
|
|
{
|
|
|
|
private static CommandResetDungeons instance = null;
|
|
|
|
|
|
|
|
private CommandResetDungeons()
|
|
|
|
{
|
|
|
|
super("dd-resetdungeons", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CommandResetDungeons instance()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
instance = new CommandResetDungeons();
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
|
|
|
{
|
2013-11-06 00:15:23 +01:00
|
|
|
if(sender.worldObj.isRemote)
|
|
|
|
{
|
|
|
|
return DDCommandResult.SUCCESS;
|
|
|
|
}
|
2013-06-25 20:28:11 +02:00
|
|
|
if (command.length > 0)
|
|
|
|
{
|
|
|
|
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dungeonCount = 0;
|
|
|
|
int resetCount = 0;
|
2013-11-06 00:15:23 +01:00
|
|
|
ArrayList<Integer> dimsToDelete = new ArrayList<Integer>();
|
|
|
|
ArrayList<Integer> dimsToFix = new ArrayList<Integer>();
|
|
|
|
|
|
|
|
for (NewDimData data : PocketManager.getDimensions())
|
2013-06-25 20:28:11 +02:00
|
|
|
{
|
2013-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
if(DimensionManager.getWorld(data.id())==null&&data.isDungeon())
|
|
|
|
{
|
|
|
|
resetCount++;
|
|
|
|
dungeonCount++;
|
|
|
|
dimsToDelete.add(data.id());
|
|
|
|
}
|
|
|
|
else if(data.isDungeon())
|
2013-06-25 20:28:11 +02:00
|
|
|
{
|
2013-11-06 00:15:23 +01:00
|
|
|
dimsToFix.add(data.id());
|
2013-06-25 20:28:11 +02:00
|
|
|
dungeonCount++;
|
2013-11-06 00:15:23 +01:00
|
|
|
for(DimLink link : data.links())
|
2013-06-25 20:28:11 +02:00
|
|
|
{
|
2013-11-06 00:15:23 +01:00
|
|
|
if(link.linkType()==LinkTypes.REVERSE)
|
|
|
|
{
|
|
|
|
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
|
|
|
|
}
|
|
|
|
if(link.linkType()==LinkTypes.DUNGEON)
|
|
|
|
{
|
|
|
|
data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation());
|
|
|
|
}
|
2013-06-25 20:28:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
for(Integer dimID:dimsToDelete)
|
|
|
|
{
|
|
|
|
PocketManager.deletePocket(PocketManager.getDimensionData(dimID), true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* temporary workaround
|
|
|
|
*/
|
|
|
|
for(Integer dimID: dimsToFix)
|
|
|
|
{
|
|
|
|
PocketManager.getDimensionData(dimID).setParentToRoot();
|
|
|
|
}
|
|
|
|
//TODO- for some reason the parent field of loaded dimenions get reset to null if I call .setParentToRoot() before I delete the pockets.
|
|
|
|
//TODO implement blackList
|
2013-06-25 20:28:11 +02:00
|
|
|
//Notify the user of the results
|
2013-11-06 22:40:49 +01:00
|
|
|
sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset."));
|
2013-06-25 20:28:11 +02:00
|
|
|
return DDCommandResult.SUCCESS;
|
|
|
|
}
|
2013-11-06 22:40:49 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCommandUsage(ICommandSender icommandsender) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
2013-06-25 20:28:11 +02:00
|
|
|
}
|