Partially Overhauled Commands

Partially overhauled our command classes. Added DDCommandBase - it
extends CommandBase and acts as a new base class for our commands. It
removes a little redundancy in our code and provides increased
convenience. Removed the static fields for our commands in
mod_pocketDim. There was no point in keeping them when nothing was using
them. Changed in-game command names to be shorter yet relevant.
Converted all commands to singletons so proper instances can be
retrieved if necessary. Migrated some of the custom dungeon start/ending
logic to DungeonHelper and made customDungeonStatus private. Except for
data objects, we shouldn't be exposing state variables like that without
any kind of checks. I've rewritten the code in some commands but it's
been quite tiring. Still need to fix up lots of things.
This commit is contained in:
SenseiKiwi 2013-06-18 10:23:31 -04:00
parent 45e039573b
commit ecaa90a438
12 changed files with 365 additions and 487 deletions

View file

@ -1,146 +0,0 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.util.Collection;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.MathHelper;
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
public class CommandAddDungeonRift extends CommandBase
{
public String getCommandName()//the name of our command
{
return "dimdoors-genDungeonRift";
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
{
DungeonHelper dungeonHelper = DungeonHelper.instance();
if(var2==null||this.getCommandSenderAsPlayer(var1).worldObj.isRemote)
{
return;
}
LinkData link = new LinkData(this.getCommandSenderAsPlayer(var1).worldObj.provider.dimensionId, 0,
MathHelper.floor_double(this.getCommandSenderAsPlayer(var1).posX),
MathHelper.floor_double(this.getCommandSenderAsPlayer(var1).posY)+1,
MathHelper.floor_double(this.getCommandSenderAsPlayer(var1).posZ),
MathHelper.floor_double(this.getCommandSenderAsPlayer(var1).posX),
MathHelper.floor_double(this.getCommandSenderAsPlayer(var1).posY)+1,
MathHelper.floor_double(this.getCommandSenderAsPlayer(var1).posZ),true,3);
if(var2.length!=0&&var2[0].equals("random"))
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Created dungeon rift");
dimHelper.instance.createLink(link);
link = dimHelper.instance.createPocket(link,true, true);
}
else if (var2.length != 0 && var2[0].equals("list"))
{
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
for (String name : dungeonNames)
{
getCommandSenderAsPlayer(var1).sendChatToPlayer(name);
}
}
else if(var2.length!=0)
{
for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons)
{
String dungeonName =dungeonGen.schematicPath.toLowerCase();
if(dungeonName.contains(var2[0].toLowerCase()))
{
link = dimHelper.instance.createPocket(link,true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Genned dungeon " +dungeonName);
return;
}
}
for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons)
{
String dungeonName =dungeonGen.schematicPath.toLowerCase();
if(dungeonName.contains(var2[0].toLowerCase()))
{
link = dimHelper.instance.createPocket(link,true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Genned dungeon " +dungeonName);
return;
}
}
if(var2!=null&&!var2[0].equals("random"))
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("could not find dungeon, 'list' for list of dungeons");
}
}
else
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("invalid arguments- 'random' for random dungeon, or 'list' for dungeon names");
}
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2.length));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" rifts.");
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,97 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.util.Collection;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
public class CommandCreateDungeonRift extends DDCommandBase
{
private static CommandCreateDungeonRift instance = null;
private CommandCreateDungeonRift()
{
super("dd-rift");
}
public static CommandCreateDungeonRift instance()
{
if (instance == null)
instance = new CommandCreateDungeonRift();
return instance;
}
@Override
public void processCommand(EntityPlayer sender, String[] command)
{
DungeonHelper dungeonHelper = DungeonHelper.instance();
if(command==null||sender.worldObj.isRemote)
{
return;
}
LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0,
(int) sender.posX,
(int) sender.posY + 1,
(int) sender.posZ,
(int) sender.posX,
(int) sender.posY + 1,
(int) sender.posZ,true,3);
if(command.length!=0&&command[0].equals("random"))
{
sender.sendChatToPlayer("Created dungeon rift");
dimHelper.instance.createLink(link);
link = dimHelper.instance.createPocket(link,true, true);
}
else if (command.length != 0 && command[0].equals("list"))
{
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
for (String name : dungeonNames)
{
getCommandSenderAsPlayer(sender).sendChatToPlayer(name);
}
}
else if(command.length!=0)
{
for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons)
{
String dungeonName =dungeonGen.schematicPath.toLowerCase();
if(dungeonName.contains(command[0].toLowerCase()))
{
link = dimHelper.instance.createPocket(link,true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
sender.sendChatToPlayer("Genned dungeon " +dungeonName);
return;
}
}
for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons)
{
String dungeonName =dungeonGen.schematicPath.toLowerCase();
if(dungeonName.contains(command[0].toLowerCase()))
{
link = dimHelper.instance.createPocket(link,true, true);
dimHelper.dimList.get(link.destDimID).dungeonGenerator=dungeonGen;
sender.sendChatToPlayer("Genned dungeon " +dungeonName);
return;
}
}
if(command!=null&&!command[0].equals("random"))
{
sender.sendChatToPlayer("could not find dungeon, 'list' for list of dungeons");
}
}
else
{
sender.sendChatToPlayer("invalid arguments- 'random' for random dungeon, or 'list' for dungeon names");
}
}
}

View file

@ -2,72 +2,67 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.world.World;
public class CommandDeleteAllLinks extends CommandBase
public class CommandDeleteAllLinks extends DDCommandBase
{
public String getCommandName()//the name of our command
private static CommandDeleteAllLinks instance = null;
private CommandDeleteAllLinks()
{
return "dimdoors-deleteLinksInDim";
super("dd-deletelinks");
}
public static CommandDeleteAllLinks instance()
{
if (instance == null)
instance = new CommandDeleteAllLinks();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
int linksRemoved=0;
int targetDim;
boolean shouldGo= true;
if(var2.length==0)
if(command.length==0)
{
targetDim= this.getCommandSenderAsPlayer(var1).worldObj.provider.dimensionId;
targetDim= sender.worldObj.provider.dimensionId;
}
else if(var2.length==1)
else if(command.length==1)
{
targetDim= this.parseInt(var1, var2[0]);
targetDim = parseInt(sender, command[0]);
if(!dimHelper.dimList.containsKey(targetDim))
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error- dim "+targetDim+" not registered");
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered");
shouldGo=false;
}
}
else
{
targetDim=0;
shouldGo=false;
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error-Invalid argument, delete_all_links <targetDimID> or blank for current dim");
sender.sendChatToPlayer("Error-Invalid argument, delete_all_links <targetDimID> or blank for current dim");
}
if(shouldGo)
{
if(dimHelper.dimList.containsKey(targetDim))
{
DimData dim = dimHelper.dimList.get(targetDim);
ArrayList<LinkData> linksInDim = dim.printAllLinkData();
for(LinkData link : linksInDim)
for (LinkData link : linksInDim)
{
World targetWorld = dimHelper.getWorld(targetDim);
if(targetWorld==null)
{
dimHelper.initDimension(targetDim);
@ -76,36 +71,14 @@ public class CommandDeleteAllLinks extends CommandBase
{
dimHelper.initDimension(targetDim);
}
targetWorld = dimHelper.getWorld(targetDim);
{
dim.removeLinkAtCoords(link);
targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0);
linksRemoved++;
}
dim.removeLinkAtCoords(link);
targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0);
linksRemoved++;
}
//dim.linksInThisDim.clear();
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" links.");
sender.sendChatToPlayer("Removed " + linksRemoved + " links.");
}
}
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2.length));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" rifts.");
// TODO Auto-generated method stub
}
}

View file

@ -3,60 +3,55 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import java.util.Collection;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.world.World;
public class CommandDeleteDimData extends CommandBase
public class CommandDeleteDimensionData extends DDCommandBase
{
public String getCommandName()//the name of our command
private static CommandDeleteDimensionData instance = null;
private CommandDeleteDimensionData()
{
return "dimdoors-deleteDimData";
super("dd-deletedimension");
}
public static CommandDeleteDimensionData instance()
{
if (instance == null)
instance = new CommandDeleteDimensionData();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
int linksRemoved=0;
int targetDim;
boolean shouldGo= true;
if(var2.length==0)
if (command.length==0)
{
targetDim= this.getCommandSenderAsPlayer(var1).worldObj.provider.dimensionId;
targetDim= sender.worldObj.provider.dimensionId;
}
else if(var2.length==1)
else if (command.length==1)
{
targetDim= this.parseInt(var1, var2[0]);
targetDim = parseInt(sender, command[0]);
if(!dimHelper.dimList.containsKey(targetDim))
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error- dim "+targetDim+" not registered");
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered");
shouldGo=false;
}
}
else
{
targetDim=0;
shouldGo=false;
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error-Invalid argument, delete_dim_data <targetDimID> or blank for current dim");
sender.sendChatToPlayer("Error-Invalid argument, delete_dim_data <targetDimID> or blank for current dim");
}
if(shouldGo)
{
if(dimHelper.dimList.containsKey(targetDim))
@ -65,7 +60,7 @@ public class CommandDeleteDimData extends CommandBase
{
for(DimData dimData :dimHelper.dimList.values())
{
Collection<LinkData> links= new ArrayList();
Collection<LinkData> links= new ArrayList<LinkData>();
links.addAll( dimData.printAllLinkData());
for(LinkData link : links)
@ -80,33 +75,20 @@ public class CommandDeleteDimData extends CommandBase
linksRemoved++;
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
dimHelper.dimList.remove(targetDim);
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed dimension "+targetDim+" from DimDoors and deleted "+linksRemoved+" links");
sender.sendChatToPlayer("Removed dimension " + targetDim + " from DimDoors and deleted " + linksRemoved + " links");
}
else
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error- dimension "+targetDim+" not registered with dimDoors");
}
sender.sendChatToPlayer("Error- dimension "+targetDim+" not registered with dimDoors");
}
}
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2.length));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" rifts.");
// TODO Auto-generated method stub
}
}

View file

@ -2,78 +2,68 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import cpw.mods.fml.common.FMLCommonHandler;
import StevenDimDoors.mod_pocketDim.DDProperties;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.world.World;
public class CommandDeleteRifts extends CommandBase
public class CommandDeleteRifts extends DDCommandBase
{
public CommandDeleteRifts()
private static CommandDeleteRifts instance = null;
private CommandDeleteRifts()
{
if (properties == null)
properties = DDProperties.instance();
super("dd-???");
}
private static DDProperties properties = null;
public String getCommandName()
public static CommandDeleteRifts instance()
{
return "dimdoors-cleanupRifts";
if (instance == null)
instance = new CommandDeleteRifts();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
int linksRemoved=0;
int targetDim;
boolean shouldGo= true;
if(var2.length==0)
if(command.length==0)
{
targetDim= this.getCommandSenderAsPlayer(var1).worldObj.provider.dimensionId;
targetDim= sender.worldObj.provider.dimensionId;
}
else if(var2.length==1)
else if(command.length==1)
{
targetDim= this.parseInt(var1, var2[0]);
targetDim = parseInt(sender, command[0]);
if(!dimHelper.dimList.containsKey(targetDim))
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error- dim "+targetDim+" not registered");
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered");
shouldGo=false;
}
}
else
{
targetDim=0;
shouldGo=false;
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error-Invalid argument, delete_links <targetDimID> or blank for current dim");
sender.sendChatToPlayer("Error-Invalid argument, delete_links <targetDimID> or blank for current dim");
}
if(shouldGo)
{
if(dimHelper.dimList.containsKey(targetDim))
{
DimData dim = dimHelper.dimList.get(targetDim);
ArrayList<LinkData> linksInDim = dim.printAllLinkData();
for(LinkData link : linksInDim)
{
World targetWorld = dimHelper.getWorld(targetDim);
if(targetWorld==null)
{
dimHelper.initDimension(targetDim);
@ -81,37 +71,18 @@ public class CommandDeleteRifts extends CommandBase
else if(targetWorld.provider==null)
{
dimHelper.initDimension(targetDim);
}
targetWorld = dimHelper.getWorld(targetDim);
if(targetWorld.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord)==properties.RiftBlockID)
targetWorld = dimHelper.getWorld(targetDim);
if (targetWorld.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord) == mod_pocketDim.blockRift.blockID)
{
dim.removeLinkAtCoords(link);
targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0);
linksRemoved++;
}
}
//dim.linksInThisDim.clear();
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" rifts.");
}
sender.sendChatToPlayer("Removed "+linksRemoved+" rifts.");
}
}
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2.length));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" rifts.");
// TODO Auto-generated method stub
}
}

View file

@ -2,91 +2,79 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.io.File;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
public class CommandEndDungeonCreation extends CommandBase
{
private static DDProperties properties = null;
public class CommandEndDungeonCreation extends DDCommandBase
{
private static CommandEndDungeonCreation instance = null;
public CommandEndDungeonCreation()
private CommandEndDungeonCreation()
{
if (properties == null)
properties = DDProperties.instance();
super("dd-export");
}
public String getCommandName()//the name of our command
public static CommandEndDungeonCreation instance()
{
return "dimdoors-endDungeonCreation";
if (instance == null)
instance = new CommandEndDungeonCreation();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
DungeonHelper dungeonHelper = DungeonHelper.instance();
DDProperties properties = DDProperties.instance();
EntityPlayer player = this.getCommandSenderAsPlayer(var1);
if (!dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId))
if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId))
{
if (var2.length < 2)
if (command.length < 2)
{
player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
return;
}
else if (!var2[1].contains("OVERRIDE"))
else if (!command[1].contains("OVERRIDE"))
{
player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
sender.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway");
return;
}
}
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
int x = (int) sender.posX;
int y = (int) sender.posY;
int z = (int) sender.posZ;
if(var2.length==0)
if (command.length == 0)
{
player.sendChatToPlayer("Must name file");
sender.sendChatToPlayer("Must name file");
}
else if(!player.worldObj.isRemote)
else if(!sender.worldObj.isRemote)
{
//Check that the dungeon name is valid to prevent directory traversal and other forms of abuse
if (DungeonHelper.NamePattern.matcher(var2[0]).matches())
if (DungeonHelper.NamePattern.matcher(command[0]).matches())
{
String exportPath = properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic";
if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath))
String exportPath = properties.CustomSchematicDirectory + "/" + command[0] + ".schematic";
if (dungeonHelper.exportDungeon(sender.worldObj, x, y, z, exportPath))
{
player.sendChatToPlayer("Saved dungeon schematic in " + exportPath);
sender.sendChatToPlayer("Saved dungeon schematic in " + exportPath);
dungeonHelper.registerCustomDungeon(new File(exportPath));
if (dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote)
{
// mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId);
// dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player);
}
}
else
{
player.sendChatToPlayer("Failed to save dungeon schematic!");
sender.sendChatToPlayer("Failed to save dungeon schematic!");
}
}
else
{
player.sendChatToPlayer("Invalid schematic name. Please use only letters, numbers, and underscores.");
sender.sendChatToPlayer("Invalid schematic name. Please use only letters, numbers, and underscores.");
}
}
// TODO Auto-generated method stub
}
}

View file

@ -3,91 +3,68 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import java.util.Collection;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.world.World;
public class CommandPrintDimData extends CommandBase
public class CommandPrintDimensionData extends DDCommandBase
{
public String getCommandName()//the name of our command
private static CommandPrintDimensionData instance = null;
private CommandPrintDimensionData()
{
return "dimdoors-printDimData";
super("dd-dimensiondata");
}
public static CommandPrintDimensionData instance()
{
if (instance == null)
instance = new CommandPrintDimensionData();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
int linksRemoved=0;
int targetDim;
boolean shouldGo= true;
if(var2.length==0)
if(command.length==0)
{
targetDim= this.getCommandSenderAsPlayer(var1).worldObj.provider.dimensionId;
targetDim= sender.worldObj.provider.dimensionId;
}
else if(var2.length==1)
else if(command.length==1)
{
targetDim= this.parseInt(var1, var2[0]);
targetDim = parseInt(sender, command[0]);
if(!dimHelper.dimList.containsKey(targetDim))
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error- dim "+targetDim+" not registered");
sender.sendChatToPlayer("Error- dim "+targetDim+" not registered");
shouldGo=false;
}
}
else
{
targetDim=0;
shouldGo=false;
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Error-Invalid argument, print_dim_data <targetDimID> or blank for current dim");
sender.sendChatToPlayer("Error-Invalid argument, print_dim_data <targetDimID> or blank for current dim");
}
if(shouldGo)
{
if(dimHelper.dimList.containsKey(targetDim))
{
DimData dimData = dimHelper.dimList.get(targetDim);
Collection<LinkData> links= new ArrayList();
links.addAll( dimData.printAllLinkData());
for(LinkData link : links)
{
this.getCommandSenderAsPlayer(var1).sendChatToPlayer( link.printLinkData());
}
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("DimID= "+dimData.dimID+"Dim depth = "+dimData.depth);
Collection<LinkData> links = new ArrayList<LinkData>();
links.addAll( dimData.printAllLinkData());
for (LinkData link : links)
{
sender.sendChatToPlayer(link.printLinkData());
}
}
else
{
}
}
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer(String.valueOf(var2.length));
// this.getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+linksRemoved+" rifts.");
// TODO Auto-generated method stub
sender.sendChatToPlayer("DimID= "+dimData.dimID+"Dim depth = "+dimData.depth);
}
}
}
}

View file

@ -3,29 +3,37 @@ package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
public class CommandPruneDims extends CommandBase
public class CommandPruneDimensions extends DDCommandBase
{
public String getCommandName()//the name of our command
private static CommandPruneDimensions instance = null;
private CommandPruneDimensions()
{
return "dimdoors-prunePockets";
super("dd-prune");
}
public static CommandPruneDimensions instance()
{
if (instance == null)
instance = new CommandPruneDimensions();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
int numRemoved=0;
ArrayList dimsWithLinks=new ArrayList();
Collection<DimData> allDims = new ArrayList();
ArrayList<Integer> dimsWithLinks = new ArrayList<Integer>();
Collection<DimData> allDims = new ArrayList<DimData>();
allDims.addAll(dimHelper.dimList.values());
for(DimData data: allDims)
{
for(LinkData link:data.printAllLinkData())
{
if(!dimsWithLinks.contains(link.destDimID))
@ -34,7 +42,6 @@ public class CommandPruneDims extends CommandBase
}
}
}
for(LinkData link : dimHelper.instance.interDimLinkList.values())
{
if(!dimsWithLinks.contains(link.destDimID))
@ -42,7 +49,6 @@ public class CommandPruneDims extends CommandBase
dimsWithLinks.add(link.destDimID);
}
}
for(DimData data : allDims)
{
if(!dimsWithLinks.contains(data.dimID))
@ -52,6 +58,6 @@ public class CommandPruneDims extends CommandBase
}
}
dimHelper.instance.save();
getCommandSenderAsPlayer(var1).sendChatToPlayer("Removed "+numRemoved+" unreachable pocket dims.");
sender.sendChatToPlayer("Removed " + numRemoved + " unreachable pocket dims.");
}
}

View file

@ -1,62 +1,40 @@
package StevenDimDoors.mod_pocketDim.commands;
import java.util.ArrayList;
import cpw.mods.fml.common.FMLCommonHandler;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DimData;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
import StevenDimDoors.mod_pocketDim.items.itemDimDoor;
import net.minecraft.block.Block;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
public class CommandStartDungeonCreation extends CommandBase
public class CommandStartDungeonCreation extends DDCommandBase
{
public CommandStartDungeonCreation()
private static CommandStartDungeonCreation instance = null;
private CommandStartDungeonCreation()
{
if (properties == null)
properties = DDProperties.instance();
super("dd-create");
}
private static DDProperties properties = null;
public String getCommandName()//the name of our command
public static CommandStartDungeonCreation instance()
{
return "dimdoors-startDungeonCreation";
if (instance == null)
instance = new CommandStartDungeonCreation();
return instance;
}
@Override
public void processCommand(ICommandSender var1, String[] var2)
protected void processCommand(EntityPlayer sender, String[] command)
{
EntityPlayer player = this.getCommandSenderAsPlayer(var1);
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
if(!player.worldObj.isRemote)
if (!sender.worldObj.isRemote)
{
LinkData link = new LinkData(player.worldObj.provider.dimensionId, 0, x, y+1, z, x, y+1, z, true, 3);
link = dimHelper.instance.createPocket(link,true, false);
//Place a door leading to a pocket dimension where the player is standing.
//The pocket dimension will be serve as a room for the player to build a dungeon.
int x = (int) sender.posX;
int y = (int) sender.posY;
int z = (int) sender.posZ;
LinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z);
itemDimDoor.placeDoorBlock(player.worldObj, x, y, z, 3, Block.blocksList[properties.WarpDoorID]);
// dimHelper.instance.teleportToPocket(player.worldObj, link, player);
DungeonHelper.instance().customDungeonStatus.put(link.destDimID, dimHelper.instance.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID));
this.getCommandSenderAsPlayer(var1).sendChatToPlayer("DimID = "+ link.destDimID);
//Notify the player
sender.sendChatToPlayer("Created a door to a pocket dimension (ID = " + link.destDimID + "). Please build your dungeon there.");
}
}
}

View file

@ -0,0 +1,48 @@
package StevenDimDoors.mod_pocketDim.commands;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
/*
* An abstract base class for our Dimensional Doors commands. This cleans up the code a little and provides
* some convenience improvements.
*/
public abstract class DDCommandBase extends CommandBase
{
private String name;
public DDCommandBase(String name)
{
this.name = name;
}
/*
* When overridden in a derived class, processes the command sent by the server.
*/
protected abstract void processCommand(EntityPlayer sender, String[] command);
public final String getCommandName()
{
return name;
}
/*
* Registers the command at server startup.
*/
public void register(FMLServerStartingEvent event)
{
event.registerServerCommand(this);
}
/*
* Method invoked by the server to execute a command. The call is forwarded to a derived class
* to provide the sending player directly.
*/
public final void processCommand(ICommandSender sender, String[] command)
{
//Forward the command
processCommand(getCommandSenderAsPlayer(sender), command);
}
}

View file

@ -24,6 +24,7 @@ import StevenDimDoors.mod_pocketDim.helpers.jnbt.ListTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag;
import StevenDimDoors.mod_pocketDim.items.itemDimDoor;
import StevenDimDoors.mod_pocketDim.util.WeightedContainer;
public class DungeonHelper
@ -58,7 +59,7 @@ public class DungeonHelper
private Random rand = new Random();
public HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>();
private HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>();
public ArrayList<DungeonGenerator> customDungeons = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> registeredDungeons = new ArrayList<DungeonGenerator>();
@ -103,10 +104,10 @@ public class DungeonHelper
if (properties == null)
properties = DDProperties.instance();
initializeDungeons();
registerCustomDungeons();
}
private void initializeDungeons()
private void registerCustomDungeons()
{
File file = new File(properties.CustomSchematicDirectory);
if (file.exists() || file.mkdir())
@ -143,6 +144,28 @@ public class DungeonHelper
return instance;
}
public LinkData createCustomDungeonDoor(World world, int x, int y, int z)
{
//Create a link above the specified position. Link to a new pocket dimension.
LinkData link = new LinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3);
link = dimHelper.instance.createPocket(link, true, false);
//Place a Warp Door linked to that pocket
itemDimDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.ExitDoor);
//Register the pocket as a custom dungeon
customDungeonStatus.put(link.destDimID,
dimHelper.instance.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID));
return link;
}
public boolean isCustomDungeon(int dimensionID)
{
//TODO: Should we simply treat all pocket dimensions as valid custom dungeons? ~SenseiKiwi
return customDungeonStatus.containsKey(dimensionID);
}
public boolean validateSchematicName(String name)
{
String[] dungeonData = name.split("_");

View file

@ -6,7 +6,6 @@ import java.util.HashMap;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.command.ICommand;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
@ -23,13 +22,13 @@ import StevenDimDoors.mod_pocketDim.blocks.ChaosDoor;
import StevenDimDoors.mod_pocketDim.blocks.ExitDoor;
import StevenDimDoors.mod_pocketDim.blocks.dimDoor;
import StevenDimDoors.mod_pocketDim.blocks.dimHatch;
import StevenDimDoors.mod_pocketDim.commands.CommandAddDungeonRift;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteDimData;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteDimensionData;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts;
import StevenDimDoors.mod_pocketDim.commands.CommandEndDungeonCreation;
import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimData;
import StevenDimDoors.mod_pocketDim.commands.CommandPruneDims;
import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimensionData;
import StevenDimDoors.mod_pocketDim.commands.CommandPruneDimensions;
import StevenDimDoors.mod_pocketDim.commands.CommandStartDungeonCreation;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
@ -95,15 +94,6 @@ public class mod_pocketDim
public static SchematicLoader loader;
public static pocketTeleporter teleporter;
public static ICommand printDimData;
public static ICommand removeRiftsCommand;
public static ICommand pruneDimsCommand;
public static ICommand removeAllLinksCommand;
public static ICommand deleteDimDataCommand;
public static ICommand addDungeonRift;
public static ICommand endDungeonCreation;
public static ICommand startDungeonCreation;
public static Block transientDoor;
public static Block ExitDoor;
public static Block chaosDoor;
@ -155,15 +145,6 @@ public class mod_pocketDim
loader = new SchematicLoader();
teleporter = new pocketTeleporter();
printDimData = new CommandPrintDimData();
removeRiftsCommand = new CommandDeleteRifts();
pruneDimsCommand = new CommandPruneDims();
removeAllLinksCommand = new CommandDeleteAllLinks();
deleteDimDataCommand = new CommandDeleteDimData();
addDungeonRift = new CommandAddDungeonRift();
endDungeonCreation = new CommandEndDungeonCreation();
startDungeonCreation = new CommandStartDungeonCreation();
tracker = new PlayerRespawnTracker();
riftGen = new RiftGenerator();
}
@ -409,14 +390,14 @@ public class mod_pocketDim
@ServerStarting
public void serverStarting(FMLServerStartingEvent event)
{
event.registerServerCommand(removeRiftsCommand);
event.registerServerCommand(pruneDimsCommand);
event.registerServerCommand(removeAllLinksCommand);
event.registerServerCommand(deleteDimDataCommand);
event.registerServerCommand(addDungeonRift);
event.registerServerCommand(mod_pocketDim.startDungeonCreation);
event.registerServerCommand(mod_pocketDim.printDimData);
event.registerServerCommand(mod_pocketDim.endDungeonCreation);
CommandCreateDungeonRift.instance().register(event);
CommandDeleteAllLinks.instance().register(event);
CommandDeleteDimensionData.instance().register(event);
CommandDeleteRifts.instance().register(event);
CommandEndDungeonCreation.instance().register(event);
CommandPrintDimensionData.instance().register(event);
CommandPruneDimensions.instance().register(event);
CommandStartDungeonCreation.instance().register(event);
dimHelper.instance.load();
if(!dimHelper.dimList.containsKey(properties.LimboDimensionID))