mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Get it all working
This commit is contained in:
@ -19,19 +19,18 @@
|
||||
|
||||
package com.sk89q.worldedit.util.formatting.component;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
/**
|
||||
* Represents a fragment representing a command that is to be typed.
|
||||
*/
|
||||
public class Code extends TextComponent {
|
||||
public class Code extends TextComponentProducer {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public Code(String message) {
|
||||
super(builder(message).color(TextColor.AQUA));
|
||||
getBuilder().content(message).color(TextColor.AQUA);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ 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;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
public class CommandListBox extends MessageBox {
|
||||
@ -33,14 +35,24 @@ public class CommandListBox extends MessageBox {
|
||||
* @param title the title
|
||||
*/
|
||||
public CommandListBox(String title) {
|
||||
super(title);
|
||||
super(title, new TextComponentProducer());
|
||||
}
|
||||
|
||||
public CommandListBox appendCommand(String alias, String description) {
|
||||
return appendCommand(alias, description, null);
|
||||
}
|
||||
|
||||
public CommandListBox appendCommand(String alias, String description, String insertion) {
|
||||
if (!first) {
|
||||
getContents().append(Component.newline());
|
||||
}
|
||||
getContents().append(TextComponent.of(alias, TextColor.GOLD).append(TextComponent.of(": ")));
|
||||
TextComponent commandName = TextComponent.of(alias, TextColor.GOLD);
|
||||
if (insertion != null) {
|
||||
commandName = commandName
|
||||
.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, insertion))
|
||||
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select")));
|
||||
}
|
||||
getContents().append(commandName.append(TextComponent.of(": ")));
|
||||
getContents().append(TextComponent.of(description));
|
||||
first = false;
|
||||
return this;
|
||||
|
@ -39,7 +39,7 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* A box to describe usage of a command.
|
||||
*/
|
||||
public class CommandUsageBox extends TextComponent {
|
||||
public class CommandUsageBox extends TextComponentProducer {
|
||||
|
||||
/**
|
||||
* Create a new usage box.
|
||||
@ -59,7 +59,6 @@ public class CommandUsageBox extends TextComponent {
|
||||
* @param locals list of locals to use
|
||||
*/
|
||||
public CommandUsageBox(CommandCallable command, String commandString, @Nullable CommandLocals locals) {
|
||||
super(builder());
|
||||
checkNotNull(command);
|
||||
checkNotNull(commandString);
|
||||
if (command instanceof Dispatcher) {
|
||||
@ -82,18 +81,17 @@ public class CommandUsageBox extends TextComponent {
|
||||
}
|
||||
}
|
||||
|
||||
append(box);
|
||||
append(box.create());
|
||||
}
|
||||
|
||||
private void attachCommandUsage(Description description, String commandString) {
|
||||
MessageBox box = new MessageBox("Help for " + commandString);
|
||||
Component contents = box.getContents();
|
||||
TextComponentProducer contents = new TextComponentProducer();
|
||||
|
||||
if (description.getUsage() != null) {
|
||||
contents.append(new Label("Usage: "));
|
||||
contents.append(new Label("Usage: ").create());
|
||||
contents.append(TextComponent.of(description.getUsage()));
|
||||
} else {
|
||||
contents.append(new Subtle("Usage information is not available."));
|
||||
contents.append(new Subtle("Usage information is not available.").create());
|
||||
}
|
||||
|
||||
contents.append(Component.newline());
|
||||
@ -103,10 +101,11 @@ public class CommandUsageBox extends TextComponent {
|
||||
} else if (description.getDescription() != null) {
|
||||
contents.append(TextComponent.of(description.getDescription()));
|
||||
} else {
|
||||
contents.append(new Subtle("No further help is available."));
|
||||
contents.append(new Subtle("No further help is available.").create());
|
||||
}
|
||||
|
||||
append(box);
|
||||
MessageBox box = new MessageBox("Help for " + commandString, contents);
|
||||
append(box.create());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,19 +19,18 @@
|
||||
|
||||
package com.sk89q.worldedit.util.formatting.component;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
/**
|
||||
* Represents a fragment representing an error.
|
||||
*/
|
||||
public class Error extends TextComponent {
|
||||
public class Error extends TextComponentProducer {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public Error(String message) {
|
||||
super(builder(message).color(TextColor.RED));
|
||||
getBuilder().content(message).color(TextColor.RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,19 +19,18 @@
|
||||
|
||||
package com.sk89q.worldedit.util.formatting.component;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
/**
|
||||
* Represents a fragment representing a label.
|
||||
*/
|
||||
public class Label extends TextComponent {
|
||||
public class Label extends TextComponentProducer {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public Label(String message) {
|
||||
super(builder(message).color(TextColor.YELLOW));
|
||||
getBuilder().content(message).color(TextColor.YELLOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,17 +28,16 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
/**
|
||||
* Makes for a box with a border above and below.
|
||||
*/
|
||||
public class MessageBox extends TextComponent {
|
||||
public class MessageBox extends TextComponentProducer {
|
||||
|
||||
public static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47;
|
||||
private static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47;
|
||||
|
||||
private final Component contents = Component.empty();
|
||||
private final TextComponentProducer contents;
|
||||
|
||||
/**
|
||||
* Create a new box.
|
||||
*/
|
||||
public MessageBox(String title) {
|
||||
super(builder());
|
||||
public MessageBox(String title, TextComponentProducer contents) {
|
||||
checkNotNull(title);
|
||||
|
||||
int leftOver = GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2;
|
||||
@ -54,7 +53,7 @@ public class MessageBox extends TextComponent {
|
||||
append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW));
|
||||
}
|
||||
append(Component.newline());
|
||||
append(contents);
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
private String createBorder(int count) {
|
||||
@ -66,12 +65,17 @@ public class MessageBox extends TextComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internal contents.
|
||||
* Gets the message box contents producer.
|
||||
*
|
||||
* @return the contents
|
||||
* @return The contents producer
|
||||
*/
|
||||
public Component getContents() {
|
||||
public TextComponentProducer getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent create() {
|
||||
append(contents.create());
|
||||
return super.create();
|
||||
}
|
||||
}
|
||||
|
@ -19,19 +19,18 @@
|
||||
|
||||
package com.sk89q.worldedit.util.formatting.component;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
/**
|
||||
* Represents a subtle part of the message.
|
||||
*/
|
||||
public class Subtle extends TextComponent {
|
||||
public class Subtle extends TextComponentProducer {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public Subtle(String message) {
|
||||
super(builder(message).color(TextColor.GRAY));
|
||||
getBuilder().color(TextColor.GRAY).content(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.component;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
public class TextComponentProducer {
|
||||
|
||||
private TextComponent.Builder builder = TextComponent.builder().content("");
|
||||
|
||||
public TextComponent.Builder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a component as a child to this Producer
|
||||
*
|
||||
* @param component The component
|
||||
* @return The producer, for chaining
|
||||
*/
|
||||
public TextComponentProducer append(Component component) {
|
||||
getBuilder().append(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextComponent create() {
|
||||
return builder.build();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user