3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 18:10:08 +01:00

Use wrappers for the Format-type components

Dieser Commit ist enthalten in:
Matthew Miller 2019-04-25 19:11:58 +10:00
Ursprung 0434bcf48c
Commit 5606e752c2
11 geänderte Dateien mit 117 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -16,7 +16,6 @@
<allow pkg="net.royawesome.jlibnoise"/>
<allow pkg="org.json.simple" />
<allow pkg="org.slf4j"/>
<allow pkg="net.kyori.text"/>
<subpackage name="util.yaml">
<allow pkg="org.yaml.snakeyaml"/>

Datei anzeigen

@ -56,7 +56,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.Subtle;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -755,7 +755,7 @@ public class SelectionCommands {
} else {
CommandListBox box = new CommandListBox("Selection modes");
TextComponentProducer contents = box.getContents();
contents.append(new Subtle("Select one of the modes below:").append(Component.newline()).create());
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid");
box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");

Datei anzeigen

@ -58,14 +58,15 @@ import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.formatting.component.Code;
import com.sk89q.worldedit.util.formatting.component.CodeFormat;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
import com.sk89q.worldedit.util.formatting.component.Error;
import com.sk89q.worldedit.util.formatting.component.Subtle;
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -671,17 +672,19 @@ public class UtilityCommands {
// Box
CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal));
TextComponentProducer tip = new Subtle("");
TextComponentProducer tip = new TextComponentProducer();
tip.getBuilder().content("").color(TextColor.GRAY);
TextComponentProducer contents = box.getContents();
if (offset >= aliases.size()) {
tip.append(new Error(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).create()).append(Component.newline());
tip.append(ErrorFormat.wrap(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal))).newline();
} else {
List<CommandMapping> list = aliases.subList(offset, Math.min(offset + perPage, aliases.size()));
tip.append(TextComponent.of("Type "));
tip.append(new Code("//help ").append(TextComponent.of("<command> [<page>]")).create());
tip.append(TextComponent.of(" for more information.")).append(Component.newline());
tip.append("Type ");
tip.append(CodeFormat.wrap("//help "));
tip.append("<command> [<page>] for more information.");
tip.newline();
// Add each command
for (CommandMapping mapping : list) {

Datei anzeigen

@ -19,18 +19,30 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a fragment representing a command that is to be typed.
*/
public class Code extends TextComponentProducer {
public class CodeFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Code(String message) {
getBuilder().content(message).color(TextColor.AQUA);
private CodeFormat() {
getBuilder().content("").color(TextColor.AQUA);
}
/**
* Creates a CodeFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static Component wrap(String ... texts) {
CodeFormat code = new CodeFormat();
for (String text: texts) {
code.append(text);
}
return code.create();
}
}

Datei anzeigen

@ -19,7 +19,6 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
@ -44,7 +43,7 @@ public class CommandListBox extends MessageBox {
public CommandListBox appendCommand(String alias, String description, String insertion) {
if (!first) {
getContents().append(Component.newline());
getContents().newline();
}
TextComponent commandName = TextComponent.of(alias, TextColor.GOLD);
if (insertion != null) {
@ -53,7 +52,7 @@ public class CommandListBox extends MessageBox {
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select")));
}
getContents().append(commandName.append(TextComponent.of(": ")));
getContents().append(TextComponent.of(description));
getContents().append(description);
first = false;
return this;
}

Datei anzeigen

@ -29,7 +29,6 @@ import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import java.util.ArrayList;
import java.util.List;
@ -88,20 +87,20 @@ public class CommandUsageBox extends TextComponentProducer {
TextComponentProducer contents = new TextComponentProducer();
if (description.getUsage() != null) {
contents.append(new Label("Usage: ").create());
contents.append(TextComponent.of(description.getUsage()));
contents.append(LabelFormat.wrap("Usage: "));
contents.append(description.getUsage());
} else {
contents.append(new Subtle("Usage information is not available.").create());
contents.append(SubtleFormat.wrap("Usage information is not available."));
}
contents.append(Component.newline());
if (description.getHelp() != null) {
contents.append(TextComponent.of(description.getHelp()));
contents.append(description.getHelp());
} else if (description.getDescription() != null) {
contents.append(TextComponent.of(description.getDescription()));
contents.append(description.getDescription());
} else {
contents.append(new Subtle("No further help is available.").create());
contents.append(SubtleFormat.wrap("No further help is available."));
}
MessageBox box = new MessageBox("Help for " + commandString, contents);

Datei anzeigen

@ -19,18 +19,33 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a fragment representing an error.
*/
public class Error extends TextComponentProducer {
public class ErrorFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Error(String message) {
getBuilder().content(message).color(TextColor.RED);
private ErrorFormat() {
getBuilder().content("").color(TextColor.RED);
}
/**
* Creates an ErrorFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static Component wrap(String ... texts) {
ErrorFormat error = new ErrorFormat();
for (String component : texts) {
error.append(component);
}
return error.create();
}
}

Datei anzeigen

@ -19,18 +19,33 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a fragment representing a label.
*/
public class Label extends TextComponentProducer {
public class LabelFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Label(String message) {
getBuilder().content(message).color(TextColor.YELLOW);
private LabelFormat() {
getBuilder().content("").color(TextColor.YELLOW);
}
/**
* Creates a LabelFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static Component wrap(String ... texts) {
LabelFormat label = new LabelFormat();
for (String component : texts) {
label.append(component);
}
return label.create();
}
}

Datei anzeigen

@ -47,12 +47,12 @@ public class MessageBox extends TextComponentProducer {
append(TextComponent.of(createBorder(leftSide), TextColor.YELLOW));
}
append(Component.space());
append(TextComponent.of(title));
append(title);
append(Component.space());
if (rightSide > 0) {
append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW));
}
append(Component.newline());
newline();
this.contents = contents;
}

Datei anzeigen

@ -19,18 +19,33 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a subtle part of the message.
*/
public class Subtle extends TextComponentProducer {
public class SubtleFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Subtle(String message) {
getBuilder().color(TextColor.GRAY).content(message);
private SubtleFormat() {
getBuilder().content("").color(TextColor.GRAY);
}
/**
* Creates a SubtleFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static Component wrap(String ... texts) {
SubtleFormat subtle = new SubtleFormat();
for (String component : texts) {
subtle.append(component);
}
return subtle.create();
}
}

Datei anzeigen

@ -31,7 +31,7 @@ public class TextComponentProducer {
}
/**
* Adds a component as a child to this Producer
* Adds a component as a child to this Producer.
*
* @param component The component
* @return The producer, for chaining
@ -41,6 +41,27 @@ public class TextComponentProducer {
return this;
}
/**
* Adds a string as a child to this Producer.
*
* @param string The text
* @return The producer, for chaining
*/
public TextComponentProducer append(String string) {
getBuilder().append(TextComponent.of(string));
return this;
}
/**
* Adds a newline as a child to this Producer.
*
* @return The producer, for chaining
*/
public TextComponentProducer newline() {
getBuilder().append(Component.newline());
return this;
}
public TextComponent create() {
return builder.build();
}