Partial Overhaul of Commands
Made progress on overhauling and prettifying our commands. There are still more changes to be done for this to be functional. I need to do an intermediate commit because I want to merge in recent changes by Steven.
This commit is contained in:
@@ -12,16 +12,25 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
public abstract class DDCommandBase extends CommandBase
|
||||
{
|
||||
private String name;
|
||||
private String[] formats;
|
||||
|
||||
public DDCommandBase(String name)
|
||||
public DDCommandBase(String name, String format)
|
||||
{
|
||||
this.name = name;
|
||||
this.formats = new String[] { format };
|
||||
}
|
||||
|
||||
public DDCommandBase(String name, String[] formats)
|
||||
{
|
||||
this.name = name;
|
||||
this.formats = formats;
|
||||
}
|
||||
|
||||
/*
|
||||
* When overridden in a derived class, processes the command sent by the server.
|
||||
* When overridden in a derived class, processes the command sent by the server
|
||||
* and returns a status code and message for the result of the operation.
|
||||
*/
|
||||
protected abstract void processCommand(EntityPlayer sender, String[] command);
|
||||
protected abstract DDCommandResult processCommand(EntityPlayer sender, String[] command);
|
||||
|
||||
public final String getCommandName()
|
||||
{
|
||||
@@ -43,6 +52,21 @@ public abstract class DDCommandBase extends CommandBase
|
||||
public final void processCommand(ICommandSender sender, String[] command)
|
||||
{
|
||||
//Forward the command
|
||||
processCommand(getCommandSenderAsPlayer(sender), command);
|
||||
EntityPlayer player = getCommandSenderAsPlayer(sender);
|
||||
DDCommandResult result = processCommand(player, command);
|
||||
|
||||
//If the command failed, send the player a status message.
|
||||
if (result.failed())
|
||||
{
|
||||
if (result.shouldPrintUsage())
|
||||
{
|
||||
//Send the argument formats for this command
|
||||
for (String format : formats)
|
||||
{
|
||||
player.sendChatToPlayer("Usage: " + name + " " + format);
|
||||
}
|
||||
}
|
||||
player.sendChatToPlayer(result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user