3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-09 21:10:05 +01:00

Improved re-use of command help formatting.

Dieser Commit ist enthalten in:
sk89q 2014-06-30 22:08:08 -07:00
Ursprung 1e2523ddcb
Commit c29ca03e35
8 geänderte Dateien mit 169 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -41,13 +41,13 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.command.CommandCallable; import com.sk89q.worldedit.util.command.CommandCallable;
import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.PrimaryAliasComparator; import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.util.formatting.Cmd; import com.sk89q.worldedit.util.formatting.components.Code;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; 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.components.CommandUsageBox;
import com.sk89q.worldedit.util.formatting.Style; import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment; import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -623,7 +623,7 @@ public class UtilityCommands {
List<CommandMapping> list = aliases.subList(offset, Math.min(offset + perPage, aliases.size())); List<CommandMapping> list = aliases.subList(offset, Math.min(offset + perPage, aliases.size()));
tip.append("Type "); tip.append("Type ");
tip.append(new Cmd().append("//help ").append("<command> [<page>]")); tip.append(new Code().append("//help ").append("<command> [<page>]"));
tip.append(" for more information.").newLine(); tip.append(" for more information.").newLine();
// Add each command // Add each command
@ -643,28 +643,8 @@ public class UtilityCommands {
actor.printRaw(ColorCodeBuilder.asColorCodes(box)); actor.printRaw(ColorCodeBuilder.asColorCodes(box));
} else { } else {
CommandListBox box = new CommandListBox(String.format("Help: %s", Joiner.on(" ").join(visited))); String title = String.format("Help: %s", Joiner.on(" ").join(visited));
StyledFragment contents = box.getContents(); CommandUsageBox box = new CommandUsageBox(callable.getDescription(), title);
Description description = callable.getDescription();
if (description.getUsage() != null) {
contents.createFragment(Style.YELLOW).append("Usage: ");
contents.append(description.getUsage());
} else {
contents.createFragment(Style.GRAY).append("Usage information is not available.");
}
contents.newLine();
if (description.getHelp() != null) {
contents.createFragment(Style.YELLOW_DARK).append(description.getHelp());
} else if (description.getShortDescription() != null) {
contents.createFragment(Style.YELLOW_DARK).append(description.getShortDescription());
} else {
contents.createFragment(Style.GRAY).append("No further help is available.");
}
actor.printRaw(ColorCodeBuilder.asColorCodes(box)); actor.printRaw(ColorCodeBuilder.asColorCodes(box));
} }
} }

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.util.command;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; 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 com.sk89q.worldedit.util.formatting.StyledFragment;
import java.util.*; import java.util.*;

Datei anzeigen

@ -17,17 +17,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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. * 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. * Create a new instance.
*/ */
public Cmd() { public Code() {
super(Style.CYAN); super(Style.CYAN);
} }

Datei anzeigen

@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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 { public class CommandListBox extends MessageBox {

Datei anzeigen

@ -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."));
}
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -17,7 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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; import static com.google.common.base.Preconditions.checkNotNull;

Datei anzeigen

@ -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);
}
}