Get it all working

This commit is contained in:
Matthew Miller 2019-04-22 22:05:20 +10:00
parent 5a18ed275f
commit c52eb59d7f
14 changed files with 116 additions and 55 deletions

View File

@ -86,6 +86,7 @@ subprojects {
mavenCentral() mavenCentral()
maven { url "http://maven.sk89q.com/repo/" } maven { url "http://maven.sk89q.com/repo/" }
maven { url "http://repo.maven.apache.org/maven2" } maven { url "http://repo.maven.apache.org/maven2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
} }
} }

View File

@ -43,7 +43,6 @@ shadowJar {
include(dependency(':worldedit-core')) include(dependency(':worldedit-core'))
include(dependency('org.slf4j:slf4j-api')) include(dependency('org.slf4j:slf4j-api'))
include(dependency("org.slf4j:slf4j-jdk14")) include(dependency("org.slf4j:slf4j-jdk14"))
include(dependency("net.kyori:text-adapter-bukkit:1.0.3"))
relocate ("org.bstats", "com.sk89q.worldedit.bukkit.bstats") { relocate ("org.bstats", "com.sk89q.worldedit.bukkit.bstats") {
include(dependency("org.bstats:bstats-bukkit:1.4")) include(dependency("org.bstats:bstats-bukkit:1.4"))
} }

View File

@ -57,6 +57,7 @@ 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.Subtle;
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;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -753,18 +754,18 @@ public class SelectionCommands {
limit.ifPresent(integer -> player.print(integer + " points maximum.")); limit.ifPresent(integer -> player.print(integer + " points maximum."));
} else { } else {
CommandListBox box = new CommandListBox("Selection modes"); CommandListBox box = new CommandListBox("Selection modes");
Component contents = box.getContents(); TextComponentProducer contents = box.getContents();
contents.append(new Subtle("Select one of the modes below:").append(Component.newline())); contents.append(new Subtle("Select one of the modes below:").append(Component.newline()).create());
box.appendCommand("cuboid", "Select two corners of a cuboid"); box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid");
box.appendCommand("extend", "Fast cuboid selection mode"); box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");
box.appendCommand("poly", "Select a 2D polygon with height"); box.appendCommand("poly", "Select a 2D polygon with height", "//sel poly");
box.appendCommand("ellipsoid", "Select an ellipsoid"); box.appendCommand("ellipsoid", "Select an ellipsoid", "//sel ellipsoid");
box.appendCommand("sphere", "Select a sphere"); box.appendCommand("sphere", "Select a sphere", "//sel sphere");
box.appendCommand("cyl", "Select a cylinder"); box.appendCommand("cyl", "Select a cylinder", "//sel cyl");
box.appendCommand("convex", "Select a convex polyhedral"); box.appendCommand("convex", "Select a convex polyhedral", "//sel convex");
player.print(box); player.print(box.create());
return; return;
} }

View File

@ -62,12 +62,13 @@ import com.sk89q.worldedit.util.formatting.component.Code;
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.Error;
import com.sk89q.worldedit.util.formatting.component.Subtle;
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.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;
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 java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -670,16 +671,16 @@ 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));
Component contents = box.getContents(); TextComponentProducer tip = new Subtle("");
Component tip = contents.append(TextComponent.of("", TextColor.GRAY)); 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))).append(Component.newline()); tip.append(new Error(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).create()).append(Component.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(TextComponent.of("Type "));
tip.append(new Code("//help ").append(TextComponent.of("<command> [<page>]"))); tip.append(new Code("//help ").append(TextComponent.of("<command> [<page>]")).create());
tip.append(TextComponent.of(" for more information.")).append(Component.newline()); tip.append(TextComponent.of(" for more information.")).append(Component.newline());
// Add each command // Add each command
@ -697,10 +698,11 @@ public class UtilityCommands {
} }
} }
actor.print(box); contents.append(tip.create());
actor.print(box.create());
} else { } else {
CommandUsageBox box = new CommandUsageBox(callable, Joiner.on(" ").join(visited)); CommandUsageBox box = new CommandUsageBox(callable, Joiner.on(" ").join(visited));
actor.print(box); actor.print(box.create());
} }
} }

View File

@ -299,7 +299,7 @@ public final class CommandManager {
actor.printError("You are not permitted to do that. Are you in the right mode?"); actor.printError("You are not permitted to do that. Are you in the right mode?");
} catch (InvalidUsageException e) { } catch (InvalidUsageException e) {
if (e.isFullHelpSuggested()) { if (e.isFullHelpSuggested()) {
actor.print(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals)); actor.print(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals).create());
String message = e.getMessage(); String message = e.getMessage();
if (message != null) { if (message != null) {
actor.printError(message); actor.printError(message);

View File

@ -19,19 +19,18 @@
package com.sk89q.worldedit.util.formatting.component; package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
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 TextComponent { public class Code extends TextComponentProducer {
/** /**
* Create a new instance. * Create a new instance.
*/ */
public Code(String message) { public Code(String message) {
super(builder(message).color(TextColor.AQUA)); getBuilder().content(message).color(TextColor.AQUA);
} }
} }

View File

@ -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.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.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextColor;
public class CommandListBox extends MessageBox { public class CommandListBox extends MessageBox {
@ -33,14 +35,24 @@ public class CommandListBox extends MessageBox {
* @param title the title * @param title the title
*/ */
public CommandListBox(String title) { public CommandListBox(String title) {
super(title); super(title, new TextComponentProducer());
} }
public CommandListBox appendCommand(String alias, String description) { public CommandListBox appendCommand(String alias, String description) {
return appendCommand(alias, description, null);
}
public CommandListBox appendCommand(String alias, String description, String insertion) {
if (!first) { if (!first) {
getContents().append(Component.newline()); 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)); getContents().append(TextComponent.of(description));
first = false; first = false;
return this; return this;

View File

@ -39,7 +39,7 @@ import javax.annotation.Nullable;
/** /**
* A box to describe usage of a command. * A box to describe usage of a command.
*/ */
public class CommandUsageBox extends TextComponent { public class CommandUsageBox extends TextComponentProducer {
/** /**
* Create a new usage box. * Create a new usage box.
@ -59,7 +59,6 @@ public class CommandUsageBox extends TextComponent {
* @param locals list of locals to use * @param locals list of locals to use
*/ */
public CommandUsageBox(CommandCallable command, String commandString, @Nullable CommandLocals locals) { public CommandUsageBox(CommandCallable command, String commandString, @Nullable CommandLocals locals) {
super(builder());
checkNotNull(command); checkNotNull(command);
checkNotNull(commandString); checkNotNull(commandString);
if (command instanceof Dispatcher) { 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) { private void attachCommandUsage(Description description, String commandString) {
MessageBox box = new MessageBox("Help for " + commandString); TextComponentProducer contents = new TextComponentProducer();
Component contents = box.getContents();
if (description.getUsage() != null) { if (description.getUsage() != null) {
contents.append(new Label("Usage: ")); contents.append(new Label("Usage: ").create());
contents.append(TextComponent.of(description.getUsage())); contents.append(TextComponent.of(description.getUsage()));
} else { } else {
contents.append(new Subtle("Usage information is not available.")); contents.append(new Subtle("Usage information is not available.").create());
} }
contents.append(Component.newline()); contents.append(Component.newline());
@ -103,10 +101,11 @@ public class CommandUsageBox extends TextComponent {
} else if (description.getDescription() != null) { } else if (description.getDescription() != null) {
contents.append(TextComponent.of(description.getDescription())); contents.append(TextComponent.of(description.getDescription()));
} else { } 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());
} }
} }

View File

@ -19,19 +19,18 @@
package com.sk89q.worldedit.util.formatting.component; package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
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 TextComponent { public class Error extends TextComponentProducer {
/** /**
* Create a new instance. * Create a new instance.
*/ */
public Error(String message) { public Error(String message) {
super(builder(message).color(TextColor.RED)); getBuilder().content(message).color(TextColor.RED);
} }
} }

View File

@ -19,19 +19,18 @@
package com.sk89q.worldedit.util.formatting.component; package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
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 TextComponent { public class Label extends TextComponentProducer {
/** /**
* Create a new instance. * Create a new instance.
*/ */
public Label(String message) { public Label(String message) {
super(builder(message).color(TextColor.YELLOW)); getBuilder().content(message).color(TextColor.YELLOW);
} }
} }

View File

@ -28,17 +28,16 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/** /**
* Makes for a box with a border above and below. * 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. * Create a new box.
*/ */
public MessageBox(String title) { public MessageBox(String title, TextComponentProducer contents) {
super(builder());
checkNotNull(title); checkNotNull(title);
int leftOver = GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2; 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(TextComponent.of(createBorder(rightSide), TextColor.YELLOW));
} }
append(Component.newline()); append(Component.newline());
append(contents); this.contents = contents;
} }
private String createBorder(int count) { 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; return contents;
} }
@Override
public TextComponent create() {
append(contents.create());
return super.create();
}
} }

View File

@ -19,19 +19,18 @@
package com.sk89q.worldedit.util.formatting.component; package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
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 TextComponent { public class Subtle extends TextComponentProducer {
/** /**
* Create a new instance. * Create a new instance.
*/ */
public Subtle(String message) { public Subtle(String message) {
super(builder(message).color(TextColor.GRAY)); getBuilder().color(TextColor.GRAY).content(message);
} }
} }

View File

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

View File

@ -102,12 +102,12 @@ project("core") {
} }
project("bukkit") { project("bukkit") {
dependencies { dependencies {
shade 'net.kyori:text-adapter-bukkit:1.0.3' shade 'net.kyori:text-adapter-bukkit:2.0.0-SNAPSHOT'
} }
} }
project("sponge") { project("sponge") {
dependencies { dependencies {
shade 'net.kyori:text-adapter-spongeapi:1.0.3' shade 'net.kyori:text-adapter-spongeapi:2.0.0-SNAPSHOT'
} }
} }