Improved re-use of command help formatting.

This commit is contained in:
sk89q
2014-06-30 22:08:08 -07:00
parent 1e2523ddcb
commit c29ca03e35
8 changed files with 169 additions and 32 deletions

View File

@ -22,7 +22,7 @@ package com.sk89q.worldedit.util.command;
import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.CommandListBox;
import com.sk89q.worldedit.util.formatting.components.CommandListBox;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import java.util.*;

View File

@ -17,17 +17,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
package com.sk89q.worldedit.util.formatting.components;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
/**
* Represents a fragment representing a command that is to be typed.
*/
public class Cmd extends StyledFragment {
public class Code extends StyledFragment {
/**
* Create a new instance.
*/
public Cmd() {
public Code() {
super(Style.CYAN);
}

View File

@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
package com.sk89q.worldedit.util.formatting.components;
import com.sk89q.worldedit.util.formatting.Style;
public class CommandListBox extends MessageBox {

View File

@ -0,0 +1,74 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting.components;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.formatting.Style;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A box to describe usage of a command.
*/
public class CommandUsageBox extends MessageBox {
/**
* Create a new box.
*
* @param description the command to describe
* @param title the title
*/
public CommandUsageBox(Description description, String title) {
super(title);
checkNotNull(description);
attachCommandUsage(description);
}
/**
* Create a new box.
*
* @param description the command to describe
*/
public CommandUsageBox(Description description) {
super("Usage Help");
checkNotNull(description);
attachCommandUsage(description);
}
private void attachCommandUsage(Description description) {
if (description.getUsage() != null) {
getContents().append(new Label().append("Usage: "));
getContents().append(description.getUsage());
} else {
getContents().append(new Subtle().append("Usage information is not available."));
}
getContents().newLine();
if (description.getHelp() != null) {
getContents().createFragment(Style.YELLOW_DARK).append(description.getHelp());
} else if (description.getShortDescription() != null) {
getContents().createFragment(Style.YELLOW_DARK).append(description.getShortDescription());
} else {
getContents().append(new Subtle().append("No further help is available."));
}
}
}

View File

@ -0,0 +1,37 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting.components;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
/**
* Represents a fragment representing a label.
*/
public class Label extends StyledFragment {
/**
* Create a new instance.
*/
public Label() {
super(Style.YELLOW);
}
}

View File

@ -17,7 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
package com.sk89q.worldedit.util.formatting.components;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -0,0 +1,37 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting.components;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
/**
* Represents a subtle part of the message.
*/
public class Subtle extends StyledFragment {
/**
* Create a new instance.
*/
public Subtle() {
super(Style.GRAY);
}
}