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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user