Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-08 04:20:06 +01:00
Use wrappers for the Format-type components
Dieser Commit ist enthalten in:
Ursprung
0434bcf48c
Commit
5606e752c2
@ -16,7 +16,6 @@
|
|||||||
<allow pkg="net.royawesome.jlibnoise"/>
|
<allow pkg="net.royawesome.jlibnoise"/>
|
||||||
<allow pkg="org.json.simple" />
|
<allow pkg="org.json.simple" />
|
||||||
<allow pkg="org.slf4j"/>
|
<allow pkg="org.slf4j"/>
|
||||||
<allow pkg="net.kyori.text"/>
|
|
||||||
|
|
||||||
<subpackage name="util.yaml">
|
<subpackage name="util.yaml">
|
||||||
<allow pkg="org.yaml.snakeyaml"/>
|
<allow pkg="org.yaml.snakeyaml"/>
|
||||||
|
@ -56,7 +56,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
|||||||
import com.sk89q.worldedit.util.Countable;
|
import com.sk89q.worldedit.util.Countable;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
|
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.util.formatting.component.TextComponentProducer;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
@ -755,7 +755,7 @@ public class SelectionCommands {
|
|||||||
} else {
|
} else {
|
||||||
CommandListBox box = new CommandListBox("Selection modes");
|
CommandListBox box = new CommandListBox("Selection modes");
|
||||||
TextComponentProducer contents = box.getContents();
|
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("cuboid", "Select two corners of a cuboid", "//sel cuboid");
|
||||||
box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");
|
box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");
|
||||||
|
@ -58,14 +58,15 @@ import com.sk89q.worldedit.util.command.CommandMapping;
|
|||||||
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.binding.Text;
|
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.CommandListBox;
|
||||||
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
|
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
|
||||||
import com.sk89q.worldedit.util.formatting.component.Error;
|
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
|
||||||
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.util.formatting.component.TextComponentProducer;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
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.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
@ -671,17 +672,19 @@ public class UtilityCommands {
|
|||||||
|
|
||||||
// Box
|
// Box
|
||||||
CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal));
|
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();
|
TextComponentProducer contents = box.getContents();
|
||||||
|
|
||||||
if (offset >= aliases.size()) {
|
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 {
|
} else {
|
||||||
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(TextComponent.of("Type "));
|
tip.append("Type ");
|
||||||
tip.append(new Code("//help ").append(TextComponent.of("<command> [<page>]")).create());
|
tip.append(CodeFormat.wrap("//help "));
|
||||||
tip.append(TextComponent.of(" for more information.")).append(Component.newline());
|
tip.append("<command> [<page>] for more information.");
|
||||||
|
tip.newline();
|
||||||
|
|
||||||
// Add each command
|
// Add each command
|
||||||
for (CommandMapping mapping : list) {
|
for (CommandMapping mapping : list) {
|
||||||
|
@ -19,18 +19,30 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.formatting.component;
|
package com.sk89q.worldedit.util.formatting.component;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a fragment representing a command that is to be typed.
|
* Represents a fragment representing a command that is to be typed.
|
||||||
*/
|
*/
|
||||||
public class Code extends TextComponentProducer {
|
public class CodeFormat extends TextComponentProducer {
|
||||||
|
|
||||||
|
private CodeFormat() {
|
||||||
|
getBuilder().content("").color(TextColor.AQUA);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Creates a CodeFormat with the given message.
|
||||||
|
*
|
||||||
|
* @param texts The text
|
||||||
|
* @return The Component
|
||||||
*/
|
*/
|
||||||
public Code(String message) {
|
public static Component wrap(String ... texts) {
|
||||||
getBuilder().content(message).color(TextColor.AQUA);
|
CodeFormat code = new CodeFormat();
|
||||||
|
for (String text: texts) {
|
||||||
|
code.append(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return code.create();
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.formatting.component;
|
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.TextComponent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
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) {
|
public CommandListBox appendCommand(String alias, String description, String insertion) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
getContents().append(Component.newline());
|
getContents().newline();
|
||||||
}
|
}
|
||||||
TextComponent commandName = TextComponent.of(alias, TextColor.GOLD);
|
TextComponent commandName = TextComponent.of(alias, TextColor.GOLD);
|
||||||
if (insertion != null) {
|
if (insertion != null) {
|
||||||
@ -53,7 +52,7 @@ public class CommandListBox extends MessageBox {
|
|||||||
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select")));
|
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select")));
|
||||||
}
|
}
|
||||||
getContents().append(commandName.append(TextComponent.of(": ")));
|
getContents().append(commandName.append(TextComponent.of(": ")));
|
||||||
getContents().append(TextComponent.of(description));
|
getContents().append(description);
|
||||||
first = false;
|
first = false;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ 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.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -88,20 +87,20 @@ public class CommandUsageBox extends TextComponentProducer {
|
|||||||
TextComponentProducer contents = new TextComponentProducer();
|
TextComponentProducer contents = new TextComponentProducer();
|
||||||
|
|
||||||
if (description.getUsage() != null) {
|
if (description.getUsage() != null) {
|
||||||
contents.append(new Label("Usage: ").create());
|
contents.append(LabelFormat.wrap("Usage: "));
|
||||||
contents.append(TextComponent.of(description.getUsage()));
|
contents.append(description.getUsage());
|
||||||
} else {
|
} else {
|
||||||
contents.append(new Subtle("Usage information is not available.").create());
|
contents.append(SubtleFormat.wrap("Usage information is not available."));
|
||||||
}
|
}
|
||||||
|
|
||||||
contents.append(Component.newline());
|
contents.append(Component.newline());
|
||||||
|
|
||||||
if (description.getHelp() != null) {
|
if (description.getHelp() != null) {
|
||||||
contents.append(TextComponent.of(description.getHelp()));
|
contents.append(description.getHelp());
|
||||||
} else if (description.getDescription() != null) {
|
} else if (description.getDescription() != null) {
|
||||||
contents.append(TextComponent.of(description.getDescription()));
|
contents.append(description.getDescription());
|
||||||
} else {
|
} 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);
|
MessageBox box = new MessageBox("Help for " + commandString, contents);
|
||||||
|
@ -19,18 +19,33 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.formatting.component;
|
package com.sk89q.worldedit.util.formatting.component;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a fragment representing an error.
|
* Represents a fragment representing an error.
|
||||||
*/
|
*/
|
||||||
public class Error extends TextComponentProducer {
|
public class ErrorFormat extends TextComponentProducer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*/
|
*/
|
||||||
public Error(String message) {
|
private ErrorFormat() {
|
||||||
getBuilder().content(message).color(TextColor.RED);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,18 +19,33 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.formatting.component;
|
package com.sk89q.worldedit.util.formatting.component;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a fragment representing a label.
|
* Represents a fragment representing a label.
|
||||||
*/
|
*/
|
||||||
public class Label extends TextComponentProducer {
|
public class LabelFormat extends TextComponentProducer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*/
|
*/
|
||||||
public Label(String message) {
|
private LabelFormat() {
|
||||||
getBuilder().content(message).color(TextColor.YELLOW);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
@ -47,12 +47,12 @@ public class MessageBox extends TextComponentProducer {
|
|||||||
append(TextComponent.of(createBorder(leftSide), TextColor.YELLOW));
|
append(TextComponent.of(createBorder(leftSide), TextColor.YELLOW));
|
||||||
}
|
}
|
||||||
append(Component.space());
|
append(Component.space());
|
||||||
append(TextComponent.of(title));
|
append(title);
|
||||||
append(Component.space());
|
append(Component.space());
|
||||||
if (rightSide > 0) {
|
if (rightSide > 0) {
|
||||||
append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW));
|
append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW));
|
||||||
}
|
}
|
||||||
append(Component.newline());
|
newline();
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,18 +19,33 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.formatting.component;
|
package com.sk89q.worldedit.util.formatting.component;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a subtle part of the message.
|
* Represents a subtle part of the message.
|
||||||
*/
|
*/
|
||||||
public class Subtle extends TextComponentProducer {
|
public class SubtleFormat extends TextComponentProducer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*/
|
*/
|
||||||
public Subtle(String message) {
|
private SubtleFormat() {
|
||||||
getBuilder().color(TextColor.GRAY).content(message);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
@ -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
|
* @param component The component
|
||||||
* @return The producer, for chaining
|
* @return The producer, for chaining
|
||||||
@ -41,6 +41,27 @@ public class TextComponentProducer {
|
|||||||
return this;
|
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() {
|
public TextComponent create() {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren